#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 10;
int a[N];
int dp[3333][3333];
int n, m;
map<int,int>mp;
map<int,int>ans;
void solve() {
int n, m;cin >> n >> m;
if (n > m) {
puts("YES");return;
}
for (int i = 1; i <= n; i ++) {
cin >> a[i];
a[i] %= m;
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i ++) {
mp[a[i]] =1;
}
if (mp[0]) {
puts("YES\n");return;
}
reverse(a + 1, a + 1 + n);
for (int i = 2; i <= n; i ++) {
dp[i-1][a[i-1]] = 1;
for (int j =m-1; j >= 0; j--) {
if (dp[i-1][j]) {
dp[i][(j + a[i])%m] = 1;
}
}
for (int j = 0; j <= m; j ++) {
dp[i][j] = max(dp[i][j], dp[i-1][j]);
}
}
if (dp[n][0]) {
puts("YES");
} else
puts("NO");
}
int main() {
int t = 1;//cin >> t;
while (t--) solve();
return 0;
}
原文:https://www.cnblogs.com/Xiao-yan/p/14745596.html