#include #include #include using namespace std;int main() { int n, x; cin >> n >> x; vector A(n); for (int i = 0; i > A[i]; int INF = 1000; vector> dp(n + 1, vector(x, INF)); dp[0][0] = 0; for (int i = 0; i for (int j = 0; j //删除A[i] //dp[i][j] 前i个元素刚好满足取模x余数为j的操作数 dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1); //保留A[i] (1、加入原值不动 2、执行+1操作) //1、加入原值A[i]后,余数不变, 操作数等同于dp[i][j]。 //不删除元素且不修改其值,则可能加入后刚好满足余数要求,因此选取dp[i][j]满足条件的即可//选择此前刚好满足余数j要求的i int new_mod = (j + A[i]) % x; dp[i + 1][new_mod] = min(dp[i + 1][new_mod], dp[i][j]); //2、执行+1操作 for (int k = 0; k int new_mod2 = (j + A[i] + k) % x; dp[i + 1][new_mod2] = min(dp[i + 1][new_mod2], dp[i][j] + k); } } } for (int i = 0; i for (int j = 0; j cout } cout } cout return 0;}