Description
为了做饭,出题人拿了 k 块钱,准备去买食材。出题人准备买一只螃蟹和若干蔬菜。菜场里有 n 只螃蟹,第 i只螃蟹的价格为 c_i,美味值为 v_i,菜场里有 m 个蔬菜,第 i 个蔬菜的价格为 w_i,美味值为 p_i,求出题人的钱能换来最大的美味值。
Input
第一行三个正整数 k,n,m,
接下来 n 行,每行两个正整数 c_i,v_i,
接下来 m 行,每行两个正整数 w_i,p_i,
相邻整数均以空格分开
Output
一行一个整数,表示出题人的钱能换来最大的美味值
Sample input
23 2 2
2 3
3 4
10 10
10 10
Sample output
24
Note
all the numbers <= 3000
Time and memory limit
1s ,512M
这——题(连起来还不给我发了)怎么答,貌似是一个01背包的加强版,不过我写的有点问题
这是我写的
#include<bits/stdc++.h>
using namespace std;
int w[1010],v[1010],c[1010],p[1010],b[1010];
int main()
{
int k,m,n;
cin>>k>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>c[i]>>v[i];
}
for(int i=1;i<=m;i++)
{
cin>>w[i]>>p[i];
}
for(int ii=1;ii<=n;ii++)
{
for(int i=1;i<=m;i++)
{
for(int j=k;j>=w[i]+c[ii];j--)
{
b[j]=max(b[j],b[j-w[i]]+p[i])+v[ii];
}
}
}
cout<<b[k];
}
样例能过但其他评测点都错了
急!