标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 3805 Accepted Submission(s): 1587
/* ID: LinKArftc PROG: 3466.cpp LANG: C++ */ #include <map> #include <set> #include <cmath> #include <stack> #include <queue> #include <vector> #include <cstdio> #include <string> #include <utility> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define eps 1e-8 #define randin srand((unsigned int)time(NULL)) #define input freopen("input.txt","r",stdin) #define debug(s) cout << "s = " << s << endl; #define outstars cout << "*************" << endl; const double PI = acos(-1.0); const double e = exp(1.0); const int inf = 0x3f3f3f3f; const int INF = 0x7fffffff; typedef long long ll; const int maxn = 510; const int maxm = 5010; struct Node { int cost, need, val; } node[maxn]; int dp[maxm]; int n, m; bool cmp(Node a, Node b) { return (a.need - a.cost) < (b.need - b.cost); } int main() { //input; while (~scanf("%d %d", &n, &m)) { memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i ++) scanf("%d %d %d", &node[i].cost, &node[i].need, &node[i].val); sort (node+1, node+n+1, cmp); for (int i = 1; i <= n; i ++) { for (int j = m; j >= node[i].need; j --) { dp[j] = max(dp[j-node[i].cost] + node[i].val, dp[j]); } } printf("%d\n", dp[m]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/LinKArftc/p/4907462.html