Time Limit: 3000MS | Memory Limit: 30000KB | 64bit IO Format: %lld & %llu |
Description
You are to write a program which reads n,m,A1,A2,A3...An and C1,C2,C3...Cn corresponding to the number of Tony's coins of value A1,A2,A3...An then calculate how many prices(form 1 to m) Tony can pay use these coins.
Input
Output
Sample Input
3 10 1 2 4 2 1 1 2 5 1 4 2 1 0 0
Sample Output
8 4
模板
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 100010;
int v[N], num[N], dp[N];
int main()
{
int n, k;
while(scanf("%d %d", &n, &k),n!=0||k!=0)
{
memset(dp,-1,sizeof(dp));
dp[0]=0;
for(int i=0;i<n;i++)
{
scanf("%d", &v[i]);
}
for(int i=0;i<n;i++)
{
scanf("%d", &num[i]);
}
for(int i=0;i<n;i++)
{
for(int j=0;j<=k;j++)
{
if(dp[j]>=0)
{
dp[j]=num[i];
}
else if(j<v[i]||dp[j-v[i]]<=0)
{
dp[j]=-1;
}
else
{
dp[j]=dp[j-v[i]]-1;
}
}
}
int cnt=0;
for(int i=1;i<=k;i++)
{
if(dp[i]>=0)
{
cnt++;
}
}
printf("%d\n",cnt);
}
return 0;
}