codeforces(背包)
2017-08-15 20:17
507 查看
codeforces
发布时间: 2017年5月13日 22:40 最后更新: 2017年5月14日 16:39 时间限制: 1000ms 内存限制: 128M描述
LYD loves codeforces since there are many Russian contests. In an contest lasting for T minutes there are n problems, and for the ith problem you can get ai−di∗ti points, where ai indicates the initial points, di
indicates the points decreased per minute (count from the beginning of the contest), and ti stands for the passed minutes when you solved the problem (count from the beginning of the contest).
Now you know LYD can solve the ith problem in ci minutes. He can't perform as a multi-core processor, so he can think of only one problem at a moment. Can you help him get as many points ashe can?
输入
The first line contains two integers n,T(0≤n≤2000,0≤T≤5000).
The second line contains n integers a1,a2,..,an(0<ai≤6000).
The third line contains n integers d1,d2,..,dn(0<di≤50).
The forth line contains n integers c1,c2,..,cn(0<ci≤400).
输出
Output an integer in a single line, indicating the maximum points LYD can get.
样例输入1 复制
3 10 100 200 250 5 6 7 2 4 10
样例输出1
254
思路:对于每个题,都会随时降分,设两个题 a,b , 则对于da db ta tb ,如果能做,都能做完,该先做那个哪? 我是这样判断的:如果先做a那么总的浪费就是(at + bt) * db + at * da 若先做 b题那么总的浪费将是 (at+bt)*da + bt * db 令1式<2式,得到 at/da < bt/db
那么就得到了优先级,即
t/d小的优先,排完序后,按照0,1背包的思路判断每个题做还是不做,得到答案。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; struct node{ int score; int d; int t; double op; bool operator <(const node nd)const { return op < nd.op; } }; node a[100005]; int cash[50000]; int dp[100050]; int main() { int n,T; scanf("%d%d",&n,&T); for(int i = 1; i <= n; i++) scanf("%d",&a[i].score); for(int i = 1; i <= n; i++) scanf("%d",&a[i].d); for(int i = 1; i <= n; i++) { scanf("%d",&a[i].t); a[i].op = a[i].t*1.0 / a[i].d; } sort(a+1,a+1+n); int max_ = -1; for(int i = 1; i <= n; i++) { for(int j = T; j >= a[i].t; j--) { dp[j] = max(dp[j],dp[j-a[i].t] + max(0,a[i].score - j*a[i].d)); max_ = max(max_,dp[j]); } } printf("%d\n",max_); return 0; }
相关文章推荐
- codeforces 543A 完全背包
- codeforces 742D (分组背包)
- Codeforces 808E Selling Souvenirs(花费是倍数关系的背包)
- Codeforces 816E Karen And SuperMarket 树形背包
- Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp
- CodeForces - 106C (多重背包转换为01背包)
- codeforces 212E IT Restaurants(树形dp+背包思想)
- codeforces 148E Porcelain(DP, 分组背包)
- Codeforces 788C The Great Mixing(背包问题建模+bitset优化或BFS)
- codeforces189 A. Cut Ribbon【完全背包】
- CodeForces 19B Checkout Assistant (背包)
- codeforces 755F F. PolandBall and Gifts(贪心+多重背包)
- codeforces 755F PolandBall and Gifts(多重背包)
- CodeForces - 742D Arpa's weak amphitheater and Mehrdad's valuable Hoses (并查集+分组背包)
- Codeforces 864E Fire(背包DP)
- codeforces 864E Fire (排序+背包dp)
- [Codeforces 232B] Table (计数 + 背包DP)
- Codeforces 106C Buns 【0-1背包】
- Codeforces 366C Dima and Salad 背包DP
- Codeforces-815C Karen and Supermarket(树型dp+背包)