Big Event in HDU HDU - 1171

懒得写题解。简单母函数板题。
题解https://blog.csdn.net/h1021456873/article/details/50172979

#include
#include
#include
#include
using namespace std;
const int maxn=250000+10;
int c1[maxn],c2[maxn];
int v[100],num[100];
int main()
{
    int t,i,j,k,n,m;
    while(scanf("%d",&n)!=EOF) {
        m=0;
        if(n<0) break;
        for(i=1;i<=n;i++) {
            scanf("%d%d",&v[i],&num[i]);
            m+=v[i]*num[i];
        }
    memset(c1,0,sizeof(c1));
    memset(c2,0,sizeof(c2));
    c1[0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=m/2;j++)
            for(int k=0;k*v[i]+j<=m/2&&k<=num[i];k++)
                c2[j+k*v[i]]+=c1[j];
            memcpy(c1,c2,sizeof(c2));
            memset(c2,0,sizeof(c2));
    }
    int e;
    for(e=m/2;;e--)
        if(c1[e])break;
        printf("%d %d\n",m-e,e);
    }
    return 0;
}

你可能感兴趣的:(数论)