Dream City(线性DP)
描述
JAVAMAN is visiting Dream City and he sees a yard of gold coin trees. There are n trees in the yard. Let's call them tree 1, tree 2 ...and tree n. At the first day, each tree i has ai coins on it (i=1, 2, 3...n). Surprisingly, each tree i 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 most m 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 consecutive m 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.
输入
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 integers n and m (0 < m <= n <= 250) separated by a space. The second line of each test case contains n positive integers separated by a space, indicating ai. (0 < ai <= 100, i=1, 2, 3...n) The third line of each test case also contains n positive integers separated by a space, indicating bi. (0 < bi <= 100, i=1, 2, 3...n)
输出
For each test case, output the result in a single line.
样例输入
2
2 1
10 10
1 1
2 2
8 10
2 3
样例输出
10
21
提示
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.
#include <bits/stdc++.h>
using namespace std;
struct p
{
int a,b;
}x[];
int dp[];
bool cmp(p a,p b)
{
if(a.b!=b.b) return a.b<b.b;
return a.a<b.a;
}
int main()
{
ios::sync_with_stdio(false);
int T;
cin>>T;
while(T--)
{
memset(dp,,sizeof dp);
int n,m;
cin>>n>>m;
for(int i=;i<n;i++)
cin>>x[i].a;
for(int i=;i<n;i++)
cin>>x[i].b;
sort(x,x+n,cmp);
for(int i=;i<n;i++)
for(int j=m;j>;j--)
dp[j]=max(dp[j],dp[j-]+x[i].a+x[i].b*(j-));
cout<<dp[m]<<'\n';
}
return ;
}
Dream City(线性DP)的更多相关文章
- ZOJ 3211 Dream City(线性DP)
Dream City Time Limit: 1 Second Memory Limit: 32768 KB JAVAMAN is visiting Dream City and he se ...
- ZOJ 3211 Dream City(DP)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=3374 题目大意:JAVAMAN 到梦幻城市旅游见到了黄金树,黄金树上 ...
- POJ-2346 Lucky tickets(线性DP)
Lucky tickets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3298 Accepted: 2174 Descrip ...
- Hills——一道转移方程很“有趣”的线性DP
题目描述 Welcome to Innopolis city. Throughout the whole year, Innopolis citizens suffer from everlastin ...
- LightOJ1044 Palindrome Partitioning(区间DP+线性DP)
问题问的是最少可以把一个字符串分成几段,使每段都是回文串. 一开始想直接区间DP,dp[i][j]表示子串[i,j]的答案,不过字符串长度1000,100W个状态,一个状态从多个状态转移来的,转移的时 ...
- Codeforces 176B (线性DP+字符串)
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=28214 题目大意:源串有如下变形:每次将串切为两半,位置颠倒形成 ...
- hdu1712 线性dp
//Accepted 400 KB 109 ms //dp线性 //dp[i][j]=max(dp[i-1][k]+a[i][j-k]) //在前i门课上花j天得到的最大分数,等于max(在前i-1门 ...
- 动态规划——线性dp
我们在解决一些线性区间上的最优化问题的时候,往往也能够利用到动态规划的思想,这种问题可以叫做线性dp.在这篇文章中,我们将讨论有关线性dp的一些问题. 在有关线性dp问题中,有着几个比较经典而基础的模 ...
- POJ 2479-Maximum sum(线性dp)
Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33918 Accepted: 10504 Des ...
随机推荐
- android draw9patch工具使用
1.作用 将图片制作android .9图片xxx.9.png xxx.9.jpg xxx.9.gif 这些图片在android上拉伸时,边角不变形,不影响效果. 2.工具位置 Android的S ...
- android开发学习 ------- RecyclerView多类型实例
实现RecyclerView多类型的实例:效果如下图所示 public class CarFragment extends Fragment{ private View view; private R ...
- AJPFX总结面向对象(this和super的区别和应用)
面向对象(this和super的区别和应用)(掌握)* A:this和super都代表什么 * this:代表当前对象的引用,谁来调用我,我就代表谁 * super:代表当 ...
- SpringMvc返回@ResponseBody中文乱码
使用SpringMvc的@ResponseBody返回指定数据的类型做为http体向外输出,在浏览器里返回的内容里有中文,会出现乱码,项目的编码.tomcat编码等都已设置成utf-8,如下返回的是一 ...
- checkbox:click事件触发文本框显示隐藏
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Android小玩意儿-- 从头开发一个正经的MusicPlayer(二)
1·在Service中实例化MusicPlayer,实现对整个播放过程的控制 上一次做到了找到音乐数据,并封装成对象装在ArrayList里,把数据的信息显示在UI上.下面一个阶段就要开始真正的音乐播 ...
- 【HEVC帧间预测论文】P1.6 A Fast HEVC Inter CU Selection Method Based on Pyramid Motion Divergence
A Fast HEVC Inter CU Selection Method Based on Pyramid Motion Divergence <HEVC标准介绍.HEVC帧间预测论文笔记&g ...
- UVA 10900 So you want to be a 2n-aire? 2元富翁 (数学期望,贪心)
题意:你一开始有1元钱,接下来又n<=30个问题,只需答对1个问题手上的钱就翻倍,最多答对n个,得到的钱是2n.而每个问题答对的概率是[t,1]之间平均分布,那么问最优情况下得到奖金的期望值是多 ...
- mysql查询-从表1中查询出来的结果重新插入到表1
原有表结构 CREATE TABLE `t_card_user` ( `id` varchar(32) NOT NULL, `card_user_id` bigint(20) DEFAULT NULL ...
- k近邻法(kNN)
<统计学习方法>(第二版)第3章 3 分类问题中的k近邻法 k近邻法不具有显式的学习过程. 3.1 算法(k近邻法) 根据给定的距离度量,在训练集\(T\)中找出与\(x\)最邻近的\(k ...