杭电2110题 非常简单的母函数 就是套模板 贴下我的代码

#include<iostream>
#include<cstring>
using namespace std;
int c1[10005],c2[10005];
int main(void)
{
    int a[105],b[105];
    int n;
    while(cin>>n&&n)
    {
        int sum=0;
        memset(c1,0,sizeof(c1));
        memset(c2,0,sizeof(c2));
        for(int i=1;i<=n;i++)
        {
            cin>>a[i]>>b[i];
            sum+=a[i]*b[i];
        }
        if(sum%3!=0)
        {
            cout<<"sorry"<<endl;
            continue;
        }
        sum/=3;
        for(int i=0;i<=a[1]*b[1]&&i<=sum;i+=a[1])
            c1[i]=1;
        for(int i=2;i<=n;i++)
        {
            for(int j=0;j<=sum;j++)
            {
                for(int k=0;k<=a[i]*b[i];k+=a[i])
                    c2[j+k]+=c1[j];
            }
            for(int j=0;j<=sum;j++)
            {
                c1[j]=c2[j]%10000;
                c2[j]=0;
            }
        }
        if(c1[sum]==0)
            cout<<"sorry"<<endl;
        else
            cout<<c1[sum]%10000<<endl;
    }
    return 0;
}

然后具体的讲解看我搜到的大神博客
https://blog.csdn.net/yu121380/article/details/79914529