标签:des style io color ar os sp java for
2 1 1 2 1 0
1注意分步取余就好了。。虽然我不认为组合数可以超int。。#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include <deque> #include <stack> #include <map> #include <set> #define ll long long #define maxn 110 #define pp pair<int,int> #define INF 0x3f3f3f3f #define max(x,y) ( ((x) > (y)) ? (x) : (y) ) #define min(x,y) ( ((x) > (y)) ? (y) : (x) ) using namespace std; int n,v[maxn],a[16666],b[16666],num[maxn],p; void solve() { memset(a,0,sizeof(a));a[0]=1; for(int i=0;i<n;i++) { for(int j=0;j<=num[i]&&j*v[i]<=p;j++) for(int k=0;k+j*v[i]<=p;k++) b[k+j*v[i]]+=a[k]; for(int j=0;j<=p;j++) { a[j]=b[j]%10000; b[j]=0; } } if(a[p]) printf("%d\n",a[p]%10000); else puts("sorry"); } int main() { while(~scanf("%d",&n)&&n) { p=0; for(int i=0;i<n;i++) { scanf("%d%d",&v[i],&num[i]); p+=v[i]*num[i]; } if(p%3) { puts("sorry"); continue; } p/=3; solve(); } return 0; }
标签:des style io color ar os sp java for
原文地址:http://blog.csdn.net/qq_16255321/article/details/41122053