POJ-1976-A Mini Locomotive-dp】的更多相关文章

题意:给出一列火车,可以由三个火车头拉,每个火车头最多拉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",&…
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…
题目链接:http://poj.org/problem?id=3280 Time Limit: 2000MS Memory Limit: 65536K Description Keeping track of all the cows can be a tricky task so Farmer John has installed a system to automate it. He has installed on each cow an electronic ID tag that th…
题目链接: 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…
[POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted: 2222 Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, -, 2n. In each round of the tournament, all tea…
poj  3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以重复走,先用floyd预处理每个点两两之间的最短距离,然后用状态压缩DP求出走完所有点后回到原点的最短距离,用一个二进制数表示城市是否走过. 状态表示:dp[i][j]表示到达j点状态为i的最短距离 状态转移方程:dp[i][j]=min(dp[i][j],dp[j'][k]+dis[k][j]),…
poj  1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互攻击. 解析:可以发现,对于每一行放大炮的状态,只与它上面一行和上上一行的状态有关,每一行用状态压缩的表示方法,0表示不 放大炮,1表示放大炮,同样的,先要满足硬件条件,即有的地方不能放大炮,然后就是每一行中不能有两个1的距离小于 2(保证横着不互相攻击),这些要预先处理一下.然后就是状态表示和转移…
poj  3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相邻.问有多少种放牛方案(一头牛都不放也是一种方案) 解析:根据题意,把每一行的状态用二进制的数表示,0代表不在这块放牛,1表示在这一块放牛.首先很容易看到,每一行的状态要符合牧场的硬件条件,即牛必须放在能放牧的方格上.这样就能排除一些状态.另外,牛与牛之间不能相邻,这样就要求每一行中不能存在两个相邻…
/*poj 2324 Anniversary party(树形DP) ---用dp[i][1]表示以i为根的子树节点i要去的最大欢乐值,用dp[i][0]表示以i为根节点的子树i不去时的最大欢乐值, ---于是当i去时,i的所有儿子都不能去:dp[i][1]=sum(dp[j][0])+a[i],其中j是i的儿子节点. ---当i不去时,i的儿子可去也可不去:dp[i][0]=sum(max(dp[j][0],dp[j][1])),j是i的儿子节点 ---边界条件:当i时叶子节点时,dp[i][…