题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4508
//完全背包模板
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1010101;
int dp[N];
int w[N],v[N];
int main()
{
int n;
while(~scanf("%d",&n))
{
int money;
memset(dp,0,sizeof(dp));
for(int i = 1;i <= n;i ++) scanf("%d%d",&v[i],&w[i]);
scanf("%d",&money);
for(int i = 1;i <= n;i ++)
for(int j = w[i];j <= money;j ++)
{
dp[j] = max(dp[j],dp[j - w[i]] + v[i]);
}
printf("%d\n",dp[money]);
}
}