CF GYM 100703F Game of words
题意:两个人玩n个游戏,给出每人玩每个游戏的时间,两个人需要在n个游戏中挑m个轮流玩,求最短时间。
解法:dp。(这场dp真多啊……话说也可以用最小费用最大流做……然而并不会XD)dp[i][j][k]表示玩前i个游戏时第一个人玩了j个游戏,第二个人玩了k个游戏,所以状态转移方程为dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j - 1][k] + a[i], dp[i - 1][j][k - 1] + b[i]),第一个维度在空间上可以优化掉,再处理一下边界,但是如果写成dp[i][j + 1][k] = dp[i - 1][j][k] + a[i], dp[i][j][k + 1] = dp[i - 1][j][k] + b[i]看起来更优美……不需要处理边界……但是跟我的思考方式有些不同……
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
int a[405], b[405];
int dp[405][405];
int main()
{
int n, m;
while(~scanf("%d%d", &m, &n))
{
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
for(int i = 0; i < n; i++)
scanf("%d", &b[i]);
memset(dp, 0x3f3f3f3f, sizeof dp);
dp[0][0] = 0;
for(int i = 0; i < n; i++)
{
for(int j = i + 1; j >= 0; j--)
{
for(int k = i - j + 1; k >= 0; k--)
{
if(j == 0 && k == 0)
continue;
if(j == 0)
dp[j][k] = min(dp[j][k], dp[j][k - 1] + b[i]);
else if(k == 0)
dp[j][k] = min(dp[j][k], dp[j - 1][k] + a[i]);
else
dp[j][k] = min(dp[j][k], min(dp[j - 1][k] + a[i], dp[j][k - 1] + b[i]));
}
}
}
printf("%d\n", min(dp[m / 2][m - m / 2], dp[(m + 1) / 2][m - (m + 1) / 2]));
}
return 0;
}
CF GYM 100703F Game of words的更多相关文章
- CF Gym 102028G Shortest Paths on Random Forests
CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...
- CF gym 101933 K King's Colors —— 二项式反演
题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \) ...
- cf Gym 101086M ACPC Headquarters : AASTMT (Stairway to Heaven)
题目: Description standard input/output As most of you know, the Arab Academy for Science and Technolo ...
- CF Gym 100685A Ariel
传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- CF Gym 100685E Epic Fail of a Genie
传送门 E. Epic Fail of a Genie time limit per test 0.5 seconds memory limit per test 64 megabytes input ...
- CF GYM 100703A Tea-drinking
题意:龙要制作n个茶,每个茶的配方是一个字符串,两个字符串之间有一个差值,这个差值为两个字符串每个对应字母之间差的绝对值的最大值,求制作所有茶时获得的所有差值中的最大值. 解法:克鲁斯卡尔.将茶的配方 ...
- CF GYM 100703B Energy Saving
题意:王子每月买m个灯泡给n个房间换灯泡,如果当前有的灯泡数够列表的第一个房间换的就全换,直到灯泡不够为止,给出q个查询,查询x月已经换好几个房子,手里还剩多少灯泡. 解法:水题……小模拟. 代码: ...
- CF GYM 100703G Game of numbers
题意:给n个数,一开始基数为0,用这n个数依次对基数做加法或减法,使基数不超过k且不小于0,输出最远能运算到的数字个数,输出策略. 解法:dp.dp[i][j]表示做完第i个数字的运算后结果为j的可能 ...
- CF GYM 100703I Endeavor for perfection
题意:有n个学习领域,每个领域有m个课程,学习第i个领域的第j个课程可以获得sij个技能点,在每个领域中选择一个课程,要求获得的n个技能点的最大值减最小值最小,输出符合要求的策略. 解法:尺取法.将课 ...
随机推荐
- MVC5+EF6+BootStrap3.3.5 博客系统之EF(一)
- c# Oracle 远程连接方式 plsql 连接oracle 11g 64位
1.本地连接字符串: string connect = "Data Source=orcl;user=XXX;password=XXX;Persist Security Info=Tru ...
- Android导入Cocos2D的Sample项目
导入Cocos2D项目到Android的Eclipse时注意以下几点 1. Set up Variables: Eclipse->Windows->Preferences->Gene ...
- Linq基本用法
- HDU1411+四面体的体积
用cos sin各种乱搞之后 求出一个公式.. 但是怕精度损失厉害,还是暂且贴个公式的,copy别人的.. #include<stdio.h> #include<math.h> ...
- AAC ADTS AAC LATM 格式分析
http://blog.csdn.net/tx3344/article/details/7414543# 目录(?)[-] ADTS是个啥 ADTS内容及结构 将AAC打包成ADTS格式 1.ADTS ...
- java中List集合及其遍历详解
1. 首先List<E>集合继承与Collection<E>,是一个接口. ① Collection (集合框架是JDK1.2版本出现的) ② list:是有序的,元素可 ...
- Fisher's exact test( 费希尔精确检验)
Fisher's exact test[1][2][3] is a statistical significance test used in the analysis ofcontingency t ...
- laravel Authentication and Security
Creating the user modelFirst of all, we need to define the model that is going to be used to represe ...
- Git教程(2)官方命令文档及常用命令表
http://www.cnblogs.com/angeldevil/archive/2013/11/26/3238470.html 1,官方命令文档 http://www.git-scm.com/do ...