最后一道水题了。顺便水水博客,香啊。
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const int M = 11000+7;
/*
int head[M],cnt=1;
void init(){cnt=1,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,w;}ee[M*2];
void add(int x,int y,int w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;}
*/
ll f[2][M];
int w[110],nm[110];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
while(cin>>n)
{
if(n==0)break;
memset(f,0,sizeof(f));
int sm=0;
for(int i=1;i<=n;i++)cin>>w[i]>>nm[i],sm+=w[i]*nm[i];
f[0][0]=1;
int m=10000;
for(int i=1;i<=n;i++)
{
for(int j=0;j<=m;j++)f[i&1][j]=0;
for(int k=0;k<=nm[i];k++)//当前种类资产选几个
for(int x=0;x+k*w[i]<=m;x++)
f[i&1][x+k*w[i]]=(f[(i-1)&1][x]+f[i&1][x+k*w[i]])%10000;
//cout<<i<<" "<<x<<" "<<k<<" "<<x+k*w[i]<<" - - "<<f[i&1][x+k*w[i]]<<" - > "<<f[(i-1)&1][x]<<endl;;
}
ll ans=0;
if(sm%3==0)ans=f[n&1][sm/3];
if(ans)cout<<ans%10000<<endl;
else cout<<"sorry"<<endl;
}
return 0;
}