PKU--1976 A Mini Locomotive (01背包)】的更多相关文章

A Mini Locomotive Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 2485   Accepted: 1388 Description A train has a locomotive that pulls the train with its many passenger coaches. If the locomotive breaks down, there is no way to pull the…
题意:给出一列火车,可以由三个火车头拉,每个火车头最多拉m节车厢(这m节车厢需要保持连续),再给出n节车厢,每节车厢的人数,问最多能够载多少人到终点. 可以转化为三个长度相等的区间去覆盖n个数,使得这些数的和最大. 用dp[i][j]表示前i个数用j个区间覆盖所得到的最大值,状态转移则为覆盖第i个数,或者不覆盖第i个数. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm…
$dp$. 要求选择$3$个区间,使得区间和最大.$dp[i][j]$表示前$i$个数中选择了$j$段获得的最大收益. #include <cstdio> #include <cmath> #include <set> #include <cstring> #include <algorithm> using namespace std; int T,n,k; ][]; ]; int main() { scanf("%d",&…
题目链接: https://vjudge.net/problem/POJ-1976 题目描述: A train has a locomotive that pulls the train with its many passenger coaches. If the locomotive breaks down, there is no way to pull the train. Therefore, the office of railroads decided to distribute…
题意: 有一些牛,每头牛有一个Si值,一个Fi值,选出一些牛,使得max( sum(Si+Fi) ) 并且 sum(Si)>=0, sum(Fi)>=0 思路: 随便选一维做容量(比如Fi),另一维做价值,然后直接做01背包. 做的时候注意一下方向. 最后,在合法解里面找一下最优解就好了. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib>…
首先我是按这篇文章来确定题目的. poj3624 Charm Bracelet 模板题 没有要求填满,所以初始化为0就行 #include<cstdio> #include<algorithm> #include<cmath> #include<iostream> #include<cstring> using namespace std; ]; ]; int n,m; +]; int main() { // freopen("inpu…
poj3624 Charm Bracelet 模板题 没有要求填满,所以初始化为0就行 #include<cstdio> #include<iostream> using namespace std; #define N 15010 int n,m,v[N],c[N],f[N]; int main(){ scanf("%d%d",&n,&m); ;i<=n;i++) scanf("%d%d",&v[i],&…
Description A train has a locomotive that pulls the train with its many passenger coaches. If the locomotive breaks down, there is no way to pull the train. Therefore, the office of railroads decided to distribute three mini locomotives to each stati…
题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F ,     D -= K 问在D小于等于一定限度的时候最大的F. 解法: 用DP来做,如果定义dp[i][j]为前 i 个,D值为j的情况下最大的F的话,由于D值可能会增加到很大,所以是存不下的,又因为F每次最多增加20,那么1000次最多增加20000,所以开dp[1000][20000],dp[i][j]表示前 i 个,F值为j的情况下最小的D.…
Team Them Up! Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7608   Accepted: 2041   Special Judge Description Your task is to divide a number of persons into two teams, in such a way, that: everyone belongs to one of the teams; every t…