提交时间:2023-12-07 20:49:55
运行 ID: 114452
#include<iostream> using namespace std; int num[201]; bool dp[201][20001]; int main(){ int n,sum=0; cin>>n; for(int i=1;i<=n;i++){ dp[i][0]=true; } for(int i=1;i<=n;i++){ cin>>num[i]; sum+=num[i]; } if(sum%2==1){ cout<<"false"<<endl; return 0; } for(int i=1;i<=n;i++){ for(int j=1;j<=sum/2;j++){ if(j>=num[i]){ dp[i][j]=dp[i-1][j] || dp[i-1][j-num[i]]; } else dp[i][j]=dp[i-1][j]; } } if(dp[n][sum/2]==true){ cout<<"true"<<endl; } else cout<<"false"<<endl; return 0; }