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 |
Re:为什么这样理解就不对呢(测试数据都无恙的过了)In Reply To:为什么这样理解就不对呢(测试数据都无恙的过了) Posted by:hopeztm at 2012-08-13 14:35:51 > 如果理解成 价值就是重量,转换成背包问题是ok的。 > > 不过我按照“可达性”来理解做题,为什么就不对呢,代码很简单,请好心人帮看一下. > > #include <stdio.h> > #include <memory.h> > > #define MAX_CASH 100001 > struct Cash > { > int amount; > int demo; > }; > > int dp[MAX_CASH]; > int used[MAX_CASH]; > > Cash allCash[11]; > int nCash; > int nDeliver; > > int maxCash() > { > if(nCash == 0 || nDeliver == 0) > return 0; > int i,j,k; > memset(dp, 0, sizeof(dp)); > dp[0] = 1; > > for( i = 1; i <= nCash; i++) > { > memset(used, 0, sizeof(used)); > > for( j = allCash[i].demo ; j <= nDeliver; j++) > { > if(dp[j - allCash[i].demo] && > used[j - allCash[i].demo] < allCash[i].amount) > { > dp[j] = 1; > used[j] = used[j-allCash[i].demo] + 1; > } > } > } > > for( i = nDeliver; i >= 0; i--) > { > if(dp[i]) > { > return i; > } > } > return 0; > > } > > int main() > { > while(scanf("%d", &nDeliver) != EOF) > { > scanf("%d", &nCash); > for( int i = 1; i <= nCash; i++) > { > scanf("%d%d", &allCash[i].amount, &allCash[i].demo); > } > printf("%d\n", maxCash()); > } > return 0; > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator