POJ-1976-A Mini Locomotive-dp
1. Set the number of maximum passenger coaches a mini locomotive can pull, and a mini locomotive will not pull over the number. The number is same for all three locomotives.
2. With three mini locomotives, let them transport the maximum number of passengers to destination. The office already knew the number of passengers in each passenger coach, and no passengers are allowed to move between coaches.
3. Each mini locomotive pulls consecutive passenger coaches. Right after the locomotive, passenger coaches have numbers starting from 1.
For example, assume there are 7 passenger coaches, and one mini locomotive can pull a maximum of 2 passenger coaches. The number of passengers in the passenger coaches, in order from 1 to 7, is 35, 40, 50, 10, 30, 45, and 60.
If three mini locomotives pull passenger coaches 1-2, 3-4, and 6-7, they can transport 240 passengers. In this example, three mini locomotives cannot transport more than 240 passengers.
Given the number of passenger coaches, the number of passengers in each passenger coach, and the maximum number of passenger coaches which can be pulled by a mini locomotive, write a program to find the maximum number of passengers which can be transported by the three mini locomotives.
Input
The first line of the input file contains the number of passenger coaches, which will not exceed 50,000. The second line contains a list of space separated integers giving the number of passengers in each coach, such that the i th number of in this line is the number of passengers in coach i. No coach holds more than 100 passengers. The third line contains the maximum number of passenger coaches which can be pulled by a single mini locomotive. This number will not exceed 1/3 of the number of passenger coaches.
Output
Sample Input
1
7
35 40 50 10 30 45 60
2
Sample Output
240
题意:
某个车站有N个火车车厢,编号为1~N,每个车厢上有x个人。
这个车站还有三个火车头,他们能拉最多m个车厢(m<=N/3),而且这m个车厢的编号要连续的。问这三个火车头最多能拉多少个人。
参考博客:
https://blog.csdn.net/cttacm/article/details/45565447
我的代码:
#include<stdio.h>
#include<iostream>
#include<cmath>
#include<string.h>
#include<iomanip>
using namespace std;
#define inf 0x3f3f3f3f int a[];
int sum[];
int dp[][];
int main()
{
std::ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int tt;
cin>>tt;
while(tt--)
{
memset(a,,sizeof(a));
memset(sum,,sizeof(sum));
memset(dp,,sizeof(dp));
int n;
cin>>n;
for(int i=; i<=n; i++)
{
cin>>a[i];
sum[i]=sum[i-]+a[i];
}
int k;
cin>>k;
//int maxx=-inf;
for(int i=k; i<=n; i++)
{
for(int j=; j>=; j--)
{
dp[i][j]=max(dp[i-][j],dp[i-k][j-]+(sum[i]-sum[i-k]));
}
// maxx=max(dp[i],maxx);
}
cout<<dp[n][]<<endl;
}
return ;
}
POJ-1976-A Mini Locomotive-dp的更多相关文章
- POJ 1976 A Mini Locomotive【DP】
题意:给出一列火车,可以由三个火车头拉,每个火车头最多拉m节车厢(这m节车厢需要保持连续),再给出n节车厢,每节车厢的人数,问最多能够载多少人到终点. 可以转化为三个长度相等的区间去覆盖n个数,使得这 ...
- POJ 1976 A Mini Locomotive
$dp$. 要求选择$3$个区间,使得区间和最大.$dp[i][j]$表示前$i$个数中选择了$j$段获得的最大收益. #include <cstdio> #include <cma ...
- POJ1976A Mini Locomotive(01背包装+连续线段长度)
A Mini Locomotive Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2485 Accepted: 1388 ...
- POJ 3280 - Cheapest Palindrome - [区间DP]
题目链接:http://poj.org/problem?id=3280 Time Limit: 2000MS Memory Limit: 65536K Description Keeping trac ...
- A Mini Locomotive(01背包变型)
题目链接: https://vjudge.net/problem/POJ-1976 题目描述: A train has a locomotive that pulls the train with i ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- poj 3311(状态压缩DP)
poj 3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以 ...
- poj 1185(状态压缩DP)
poj 1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互 ...
- poj 3254(状态压缩DP)
poj 3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相 ...
- poj 2324 Anniversary party(树形DP)
/*poj 2324 Anniversary party(树形DP) ---用dp[i][1]表示以i为根的子树节点i要去的最大欢乐值,用dp[i][0]表示以i为根节点的子树i不去时的最大欢乐值, ...
随机推荐
- 树上莫比乌斯反演+分层图并查集——cf990G
/* 树上莫比乌斯反演 求树上 满足 d|gcd(au,av) gcd(au,av)的对数f(d) 如何求: 建立200000层新图,即对于每个数建立一个新图 在加边时,给gcd(au,av)的约数层 ...
- NX二次开发-UDO用户自定义对象(UFUN)【持续完善】
每当提起UDO总是会让我想起大专毕业那会失业找工作,后来有个宝贵机会去了软件公司上班,拿到了我人生中的第一个NX二次开发项目,一个关于测量汽车前后左右摄像头的项目.当时那个项目就用到了UDO,对于只看 ...
- hdu4352-XHXJ's LIS状压DP+数位DP
(有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 题意:传送门 原题目描述在最下面. 在区间内把整数看成一个阿拉伯数字的集合,此集合中最长严格上升子序列的长度为k的个数. 思路: ...
- 微信-小程序-开发文档-服务端-模板消息:templateMessage.send
ylbtech-微信-小程序-开发文档-服务端-模板消息:templateMessage.send 1.返回顶部 1. templateMessage.send 本接口应在服务器端调用,详细说明参见服 ...
- JAVA IntelliJ IDEA for mac/jdk的安装及环境配置、运行
现在配置完之后再回头看看,其实挺简单, 但我还是弄了好几个小时才配置出来, 不过好在是自己配置出来的, 每天都在慢慢进步. 安装及配置步骤如下: JAVA的IDE的话去jetbrains的官网上对应下 ...
- 【JUC】JDK1.8源码分析之ConcurrentHashMap
一.前言 最近几天忙着做点别的东西,今天终于有时间分析源码了,看源码感觉很爽,并且发现ConcurrentHashMap在JDK1.8版本与之前的版本在并发控制上存在很大的差别,很有必要进行认真的分析 ...
- CodeForces 1166C A Tale of Two Lands
题目链接:http://codeforces.com/problemset/problem/1166/C 题目大意 给定 n 个数,任选其中两个数 x,y,使得区间 [min(|x - y|, |x ...
- day 89 DjangoRestFramework学习三之认证组件、权限组件、频率组件、url注册器、响应器、分页组件
DjangoRestFramework学习三之认证组件.权限组件.频率组件.url注册器.响应器.分页组件 本节目录 一 认证组件 二 权限组件 三 频率组件 四 URL注册器 五 响应器 六 分 ...
- [21]APUE:线程同步之记录锁(文件)
[a] 概念 建议锁:在遵循相同记录锁规则的进程/线程间生效,通常用于保证某个程序自身多个进程/线程间的数据一致性 强制锁:意在保证所有进程间的数据一致性,但不一定有效:如不能应对先 unlink 后 ...
- 『BASH』——Learn BashScript from Daniel Robbins——[003]
ABSTRACT: Daniel Robbins is best known as the creator of Gentoo Linux and author of many IBM develop ...