提交时间:2023-12-02 09:38:46
运行 ID: 113335
#include<bits/stdc++.h> using namespace std; const int N = 105, M = 20010; int m,n,f[M],v[N],w[N],s=0; int main() { cin>>n; for(int i=1;i<=n;i++){ cin>>v[i]; w[i] = v[i]; s += w[i]; } if( s % 2 != 0 ){ cout<<"false"; return 0; } m = s / 2; for(int i=1;i<=n;i++){ for(int j=m;j>=0;j--){ if(j >= w[i]){ f[j] = max(f[j] , f[j-w[i]] + v[i]); } } } if(f[m] == s / 2) cout<<"true"; else cout<<"false"; return 0; }