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不去时的最大欢乐值, ...
随机推荐
- mysql组合查询
使用UNION 多数SQL查询都只包含一个或多个表中返回数据的单条SELECT语句.MySQL也允许执行多个查询(多条SELECT语句),并将结果作为单个查询结果集返回.这些组合查询通常称为并(uni ...
- 影响RAKsmart服务器稳定性的相关因素
RAKsmart美国服务器近年来凭借着成熟的技术和性价比吸引着广大站长,那RAKsmart服务器稳定性怎么样呢?有什么影响因素呢?下面来了解一下吧. 因素一:服务器配置 服务器能正常运营是建立在服务器 ...
- leetcode-685-冗余连接②
题目描述: 参考后提交:并查集: class Solution: def findRedundantDirectedConnection(self, edges: List[List[int]]) - ...
- Delphi 窗体的释放和判断窗体是否存在
常规释放和关闭: Form.Free - 释放Form占用的所有资源.Free后,Form指针不能再使用,除非对Form重新赋值. Form.Hide - 隐藏Form.可以调用f ...
- thinkphp自动创建目录
自动创建目录 在第一次访问应用入口文件的时候,会显示如图所示的默认的欢迎页面,并自动生成了一个默认的应用模块Home. 接下来再看原来空的Application目录下面,已经自动生成了公共模块Comm ...
- dvaJs使用注意事项
项目参考地址 dva-yicha 1. 使用路由跳转的方式 (1)所有的路由跳转功能都放到 dva/router 里面的 import { routerRedux } from 'dva/router ...
- bzoj 2257 (JSOI 2009) 瓶子与燃料
Description jyy就一直想着尽快回地球,可惜他飞船的燃料不够了. 有一天他又去向火星人要燃料,这次火星人答应了,要jyy用飞船上的瓶子来换.jyy 的飞船上共有 N个瓶子(1<=N& ...
- NX二次开发-NXOpen方式遍历所有体workPart->Bodies();
NX11+VS2013 #include <NXOpen/DisplayManager.hxx> #include <NXOpen/Body.hxx> #include < ...
- [JZOJ 5814] 树
题目:从u到v经过多少条边. 思路: 考虑他是怎么走的?? 从\(u\)到\(v\)一定是\(fa[u]\),\(fa[fa[u]]\),反正就是走\(LCA\),那么如果算出每个点到父亲的期望步数, ...
- 微信-小程序-开发文档-服务端-模板消息:templateMessage.getTemplateLibraryById
ylbtech-微信-小程序-开发文档-服务端-模板消息:templateMessage.getTemplateLibraryById 1.返回顶部 1. templateMessage.getTem ...