ZCMU新人训练赛J
来源:互联网 发布:英语听力软件高中下载 编辑:程序博客网 时间:2024/06/06 00:24
J - Dream City ZOJ - 3211
JAVAMAN is visiting Dream City and he sees a yard of gold coin trees. There are ntrees 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 growbi 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 npositive integers separated by a space, indicating bi. (0 < bi <= 100, i=1, 2, 3...n)
<b< dd="">
For each test case, output the result in a single line.
<b< dd="">
22 110 101 12 28 102 3
1021
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.
AC代码:
01背包,dp规划
#include<iostream>
#include<cstdio>
#include<string.h>
#include<cstring>
#include<queue>
#include<stdio.h>
#include<vector>
#include<set>
#include<stack>
#include<map>
#include<climits>
#include<algorithm>
using namespace std;
const int N=260;
#define LL long long
struct node
{
int a,b;
}tree[N];
bool cmp(const node a,const node b)
{
return a.b<b.b;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
cin>>tree[i].a;
for(int i=1;i<=n;i++)
cin>>tree[i].b;
sort(tree+1,tree+1+n,cmp);
int dp[N][N];
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
dp[i][j]=max(dp[i-1][j],dp[i-1][j-1]+tree[i].a+tree[i].b*(j-1));
printf("%d\n",dp[n][m]);
}
return 0;
}
- ZCMU新人训练赛J
- ZCMU新人训练赛J
- ZCMU新人训练赛A
- ZCMU新人训练赛K
- ZCMU新人训练赛A
- ZCMU新人训练赛A
- ZCMU新人训练赛B
- ZCMU新人训练赛F
- ZCMU新人训练赛I
- ZCMU新人训练赛B
- ZCMU-训练赛-A
- ZCMU-训练赛-Primary Arithmetic
- ZCMU—J
- ZCMU-训练赛-Problem A: Freckles
- TJU训练赛—J
- BNU hnust训练赛 J特殊运算
- CDOJ 数据结构训练 J
- ACdream群训练赛(38) / J - Positive Negative Sign
- 大数据生态系统基础:Apache Kafka基础(一):介绍和安装
- HashMap和HashSet的区别
- 鸡国福利 (dp)
- 世界公认最健康的作息时间表,今后就照这个来
- ASP判断select默认选中代码
- ZCMU新人训练赛J
- Android四大图片缓存(Imageloader,Picasso,Glide,Fresco)原理、特性对比
- android 线性布局设置控件固定在底部
- egret写的tips
- Nlopt库Eigen库以及MKL的使用心得
- Docker基础教程(3)Docker的简单使用
- [iOS sql数据库] 根据多个条件delete数据
- (hdu6069)2017杭电多校联赛第四场-Counting Divisors 因子个数求和(数论)
- 基于局部flush和全屏flush