| ||||||||||
| 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啊??!!!//类似于 1014
#include <iostream>
#include <string>
using namespace std;
bool dp[100005];
int n[1005], D[1005], cash, N;
int main()
{
int i, j, k, MAX;
while(scanf("%d%d",&cash, &N)!=EOF)
{
for(i=0; i<N; i++)
scanf("%d%d", n+i, D+i);
if(!cash || !N) { printf("0\n"); continue; }
memset(dp, 0, sizeof(dp));
MAX = 0; dp[0] = 1;
for(i=0; i<N; i++)
{
for(j=MAX; j>=0; j--)
{
if(dp[j])
{
for(k=1; k<=n[i] && j+k*D[i]<=cash; k++)
dp[j+k*D[i]] = 1;
}
}
MAX += n[i]*D[i];
}
i = cash;
while(!dp[i]) i--;
printf("%d\n", i);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator