zoj 3211 Dream City
来源:互联网 发布:linux xchm打不开 编辑:程序博客网 时间:2024/06/04 18:01
JAVAMAN is visiting Dream City and he sees a yard of gold coin trees. There aren trees in the yard. Let's call them tree 1, tree 2 ...and tree n. At the first day, each treei has ai coins on it (i=1, 2, 3...n). Surprisingly, each treei can grow bi new coins each day if it is not cut down. From the first day, JAVAMAN can choose to cut down one tree each day to get all the coins on it. Since he can stay in the Dream City for at mostm days, he can cut down at most m trees in all and if he decides not to cut one day, he cannot cut any trees later. (In other words, he can only cut down trees for consecutivem or less days from the first day!)
Given n, m, ai and bi (i=1, 2, 3...n), calculate the maximum number of gold coins JAVAMAN can get.
Input
There are multiple test cases. The first line of input contains an integer T (T <= 200) indicates the number of test cases. Then T test cases follow.
Each test case contains 3 lines: The first line of each test case contains 2 positive integersn and m (0 < m <= n <= 250) separated by a space. The second line of each test case containsn positive integers separated by a space, indicating ai. (0 <ai <= 100, i=1, 2, 3...n) The third line of each test case also containsn positive integers separated by a space, indicatingbi. (0 < bi <= 100, i=1, 2, 3...n)
Output
For each test case, output the result in a single line.
Sample Input
22 110 101 12 28 102 3
Sample Output
1021Hints:
Test case 1: JAVAMAN just cut tree 1 to get 10 gold coins at the first day.
Test case 2: JAVAMAN cut tree 1 at the first day and tree 2 at the second day to get 8 + 10 + 3 = 21 gold coins in all.
思路:按增长速度从小到大排序,然后直接01背包即可
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cmath>#include<cstdlib>#include<stack>#include <queue>#include <set>using namespace std;const int inf = 2147483647;const double PI = acos(-1.0);const int mod = 1000000007;struct node{int a, b, id;}x[300];bool cmp(node a, node b){//if (a.a + a.b == b.a + b.b)return a.b < b.b;//return a.a + a.b < b.a + b.b;}int dp[300];int main(){int t, i, j, n, m;scanf("%d", &t);while (t--){scanf("%d%d", &n, &m);for (i = 1; i <= n; ++i){scanf("%d", &x[i].a);}for (i = 1; i <= n; ++i)scanf("%d", &x[i].b);sort(x + 1, x + 1 + n, cmp);memset(dp, 0, sizeof(dp));for (i = 1; i <= n; ++i){for (j = m; j >= 1; --j){dp[j] = max(dp[j], dp[j - 1] + x[i].a + x[i].b * (j - 1));}}printf("%d\n", dp[m]);}}/*35 51 2 3 4 5 10 5 2 7 1*/
- ZOJ - 3211 Dream City
- zoj 3211 - Dream City
- ZOJ 3211 Dream City
- ZOJ 3211 Dream City
- zoj 3211 Dream City
- ZOJ 3211 Dream City(DP)
- ZOJ 3211Dream City(dp)
- ZOJ 3211 Dream City【dp】
- zoj 3211 Dream City 动态规划
- zoj 3211 Dream City(DP)
- zoj 3211 Dream City 贪心+动规
- ZOJ 3211 Dream City(DP)
- zoj 3211 Dream city dp+贪心
- Dream City ZOJ
- ZOJ-3211-Dream City【6th浙江省赛】【dp】
- ZOJ 3211 6th省赛 J Dream City【DP】
- zoj 3211 dream city 贪心 dp和记忆化搜索
- ZOJ-3211-Dream City-DP背包问题+贪心
- K60DN512 ADC的ab通道的问题
- 字典树应用(5)HDU1247
- 整合Acitiviti在线流程设计器(Activiti-Modeler 5.18.0)
- 表面静如处子其实动如脱兔的static
- BZOJ 3992 SDOI 2015 序列统计 NTT 生成函数 计数 原根
- zoj 3211 Dream City
- 使用Java模拟浏览器登陆网站(以抓取武汉理工大学教务处学生个人课表网页为例)
- Asp.net中配置Web.config 的UrlRewrite实现伪静态页面的代码
- redis——redis的创建与部署
- poj Dollar Dayz 3181 (DP&完全背包) 好题
- cvte暑期实习经历
- spring MVC 导出excel
- 关于C++中delete和delete[]的差别
- hibernate笔记