http://acm.hdu.edu.cn/showproblem.php?pid=4508
思路:完全背包
#include<bits/stdc++.h>
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define ll long long
#define ld long double
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lcm(a,b) ((a)*(b)/(__gcd((a),(b))))
#define mod 1000000007
#define MP make_pair
#define PI pair<int,int>
using namespace std;
const int N = 1e6 + 100;
int t, n, m, dp[N];
struct node {
int a, b;
} no[N];
int main() {
while(cin>>n) {
me(dp);
for(int i = 0; i < n; i++)
cin >> no[i].a >> no[i].b;
cin >> m;
for(int i = 0; i < n; i++) {
for(int j = no[i].b; j <= m; j++) {
dp[j] = max(dp[j], dp[j - no[i].b] + no[i].a);
}
}
cout << dp[m] << endl;
}
return 0;
}