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…
题目链接: 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…
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 station. A mini l…
 /*  题意:选出3个连续的 数的个数  为K的区间,使他们的和最大 分析: dp[j][i]=max(dp[j-k][i-1]+value[j],dp[j-1][i]);   dp[j][i]:从j个数种选出i个连续区间  数值的最大和 value[j]:第j个区间内的数的和 和背包有点像,但要活用   */   #include <cstdio> #include <cstring> #include <iostream> using namespace std;…
题目http://poj.org/problem?id=1976 分析:给n个数,求连续3段和的最大值. 这个题目的思考方式很像背包问题. dp[i][j]表示前i个数字,放在j段的最大值. 如果选了第i个数,则有 dp[i-1][j]  如果不选第i个数,由于题目是要连续的, 则有dp[i-m][j-1]+sum[i]-sum[i-m] ,这里i-m是要保证连续. dp[i][j]=max{ dp[i-1][j] ,dp[i-m][j-1]+sum[i]-sum[i-m]  } #includ…
题意:给出一列火车,可以由三个火车头拉,每个火车头最多拉m节车厢(这m节车厢需要保持连续),再给出n节车厢,每节车厢的人数,问最多能够载多少人到终点. 可以转化为三个长度相等的区间去覆盖n个数,使得这些数的和最大. 用dp[i][j]表示前i个数用j个区间覆盖所得到的最大值,状态转移则为覆盖第i个数,或者不覆盖第i个数. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm…
只写了和dp有关的..博客 https://www.cnblogs.com/huyufeifei/p/10351068.html 关于状态的继承和转移 这题的状态转移要分开两步来做: 1.继承之前状态的合法构造数量 2.构造出该状态下特有的新构造数量 这类dp尽量由已知状态推出未知态(加法转移)来做...自己用减法转移都不知道边界怎么写.. #include <cstdio> #include <algorithm> , MO = ; ], sum[N]; inline void…
电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额.如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一定可以购买成功(即使购买后卡上余额为负),否则无法购买(即使金额足够).所以大家都希望尽量使卡上的余额最少.某天,食堂中有n种菜出售,每种菜可购买一次.已知每种菜的价格以及卡上的余额,问最少可使卡上的余额为多少.   Input 多组数据.对于每组数据:第一行为正整数n,表示菜的数量.n<=1000.第二行包括n个正整数,表示每种菜的价格.价格不超过50.第三行包括一个正整数m…
$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://nanti.jisuanke.com/t/T1010 题目简述: 已知线段的两个端点的坐标A(Xa,Ya),B(Xb,Yb)A(X_a,Y_a),B(X_b,Y_b)A(Xa​,Ya​),B(Xb​,Yb​),求线段 ABAB 的长度. 蒜头君老师告诉了你计算公式如下: (Xa−Xb)2+(Ya−Yb)2\sqrt{(X_a - X_b)^2 + (Y_a - Y_b)^2}(Xa​−Xb​)2+(Ya​−Yb​)2​. 输入格式 共两行. 第一行是两个实数 Xa,Y…