fork download
  1. //----->|try=0; while(!success) try++;|<------
  2. //----->|Belief Yourself,Respect Yourself|<----
  3. //----->|Be Proud Of Yourself,You're Doing Your best|<-----
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define uniq(x) x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
  7. #define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr //Upper value search;
  8. #define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr //Lower value search;
  9. #define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
  10. #define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
  11. #define PI acos(-1.0)//PI Calculation
  12. #define LL long long
  13. #define AND(a,b) ((a) & (b))
  14. #define OR(a,b) ((a)|(b))
  15. #define XOR(a,b) ((a) ^ (b))
  16. #define mp make_pair
  17. #define sqr(x) ((x)*(x))
  18. #define sqrt(x) sqrt(1.0*(x))
  19. #define INF_MAX 2147483647
  20. #define INF_MIN -2147483647
  21. #define MX 1000005
  22. #define MOD 1000000007
  23. template<typename T> T POW(T b,T p) //Pow calculation
  24. {
  25. T r=1;
  26. while(p)
  27. {
  28. if(p&1)r=(r*b);
  29. b=(b*b);
  30. p>>=1;
  31. }
  32. return r;
  33. }
  34.  
  35. template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
  36. {
  37. T r=1;
  38. while(p)
  39. {
  40. if(p&1)r=(r*b)%m;
  41. b=(b*b)%m;
  42. p>>=1;
  43. }
  44. return r;
  45. }
  46.  
  47. //||--------------------------->||Main_Code_Start_Here||<---------------------------------||
  48. int dp[10001][10001],weight[10001],i,j;
  49. int fun(int r,int c)
  50. {
  51. if(dp[r][c]!=-1)return dp[r][c];
  52. int mx=0,t;
  53. for(int i=c;i<j;i++)
  54. {
  55. if(weight[i]<=r)
  56. {
  57. t=weight[i]+fun(r-weight[i],i+1);
  58. if(mx<t) mx=t;
  59. }
  60. }
  61. dp[r][c]=mx;
  62. return dp[r][c];
  63. }
  64. int main()
  65. {
  66. //freopen("a.in", "r", stdin);
  67. //freopen("a.out", "w", stdout);
  68. int test,arr[10001],n,len;
  69. string s;
  70. cin>>test;
  71. getchar();
  72. while(test--)
  73. {
  74. getline(cin,s);
  75. len=s.size();
  76. i=0,j=0;
  77. int sum=0;
  78. memset(dp,-1,sizeof(dp));
  79. while(i<len)
  80. {
  81. int temp=0;
  82. while(s[i]>='0' && s[i]<='9')
  83. {
  84. temp=10*temp+(s[i]-'0');
  85. i++;
  86. }
  87. weight[j++]=temp;
  88. sum+=temp;
  89. //cout<<"temp = "<<temp<<endl;
  90. i++;
  91. }
  92. if(sum%2) cout<<"NO"<<endl;
  93. else if(fun(sum/2,0)==sum/2) cout<<"YES"<<endl;
  94. else cout<<"NO"<<endl;
  95. }
  96. }
  97.  
  98.  
  99.  
Success #stdin #stdout 0.25s 394240KB
stdin
3
1 2 1 2 1
2 3 4 1 2 5 10 50 3 50
3 5 2 7 1 7 5 2 8 9 1 25 15 8 3 1 38 45 8 1
stdout
NO
YES
YES