Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
同样想法,A了In Reply To:为什么这样理解就不对呢(测试数据都无恙的过了) Posted by:hopeztm at 2012-08-13 14:35:51 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int maxn=10+2; const int maxc=100000+100; struct DE { int k,n; bool operator<(const DE &a) const { return k>a.k; } }; DE des[maxn]; int N,res; int cash; bool ss[maxc]; void work() { memset(ss,0,sizeof(ss)); ss[0]=1; for(int i=0;i<N;i++) { for(int j=cash;j>=0;j--) { if(ss[j]) { for(int k=1;k<=des[i].n;k++) { if(j+des[i].k*k<=cash) ss[j+des[i].k*k]=1; } } } } for(int i=cash;i>=0;i--) if(ss[i]) { res=i; break; } } int main() { freopen("in.txt","r",stdin); while(~scanf("%d",&cash)) { scanf("%d",&N); for(int i=0;i<N;i++) scanf("%d%d",&des[i].n,&des[i].k); work(); printf("%d\n",res); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator