Address: HDU 5000
At that time, I had this idea, that is, the attributes and values of all satisfied situations are certain. However, the number of solutions is not calculated .. (Too weak ...) At that time, I was not sure whether the guess was correct .. So I put it down... After learning about DP, find the number of solutions.
As for the guess, I cannot prove it, but I personally think that only when the sum is equal can we maintain at least one larger value by increasing or decreasing a certain number, there is at least one small one, and if it is different, one of them will eliminate the other. Therefore, the number of solutions is the largest when sum is used. Obviously, we can guess that it's half the same (it won't prove it too... If you cannot see it, you can directly find the maximum value ).
The Code is as follows:
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;int madan[3000][3000], ruo[3000];const int mod=1e9+7;int main(){ int ca, i, j, k, n, sb, ben; scanf("%d",&ca); while(ca--) { scanf("%d",&n); sb=0; for(i=1;i<=n;i++) { scanf("%d",&ruo[i]); sb+=ruo[i]; } memset(madan,0,sizeof(madan)); madan[0][0]=1; ben=0; for(i=0;i<n;i++) { for(j=0;j<=ben;j++) { if(!madan[i][j]) continue ; for(k=0;k<=ruo[i+1];k++) { madan[i+1][j+k]+=madan[i][j]; madan[i+1][j+k]%=mod; } } ben+=ruo[i+1]; } printf("%d\n",madan[n][sb/2]); } return 0;}
HDU 5000 clone)