bzoj1625

刷水題有益身心健康
dp。。。。。。。。

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s);i<=(t);i++)
inline int read(void){
    int x = 0, c, f = 1;
    do{c=getchar();if(c=='-')f=-1;}while(c<'0'||c>'9');
    do{x=x*10+c-'0';c=getchar();}while(c>='0'&&c<='9');
    return x * f;
}
int f[13880];
int main(){
    int N = read(), M = read();
    for (int i = 1; i <= N; i++) {
        int W = read(), D = read();
        for (int j = M; j >= W; j--)
            f[j] = max(f[j], f[j - W] + D);
    }
    printf("%d\n",f[M]);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章