【bzoj4580】[Usaco2016 Open]248 区间dp】的更多相关文章

4580: [Usaco2016 Open]248 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 255  Solved: 204[Submit][Status][Discuss] Description Bessie likes downloading games to play on her cell phone, even though she does find the small touch  screen rather cumbers…
题目描述 Bessie likes downloading games to play on her cell phone, even though she does find the small touch  screen rather cumbersome to use with her large hooves.She is particularly intrigued by the current g ame she is playing. The game starts with a…
n<=248个数字,可以进行这样的操作:将相邻两个相同的数字合并成这个数字+1,求最大能合成多少. f(i,j)--区间i到j能合成的最大值,f(i,j)=max(f(i,k)+1),f(i,k)=f(k+1,j). #include<stdio.h> #include<string.h> #include<algorithm> #include<stdlib.h> #include<math.h> //#include<iostre…
题目描述  给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个(数值范围1-40),问最大能合出多少.注意合并后的数值并非加倍而是+1,例如2与2合并后的数值为3. 这道题的思路: 状态: f[i][j] 代表当前 i -> j的最大值 . 初始的f[i][i] = a[i]. 然后枚举点 1 -> n-1 到 n 的区间. 然后中间再枚举断点 k. 方程就是 f[i][j] = max(f[k+1][j]+1,f[i][j]); 约束条件: 当且仅当两个区间所得到的最大值相同的时候…
https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ][j]) f[i][j] = max(f[i][k],f[k + ][j]); ); 可能f[i][k] = f[i][j],但他们可合并的并未相邻; 可以这样 #include <bits/stdc++.h> #define read read() #define up(i,l,r) for…
传送门 Description 给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个(数值范围1-40),问最大能合出多少.注意合并后的数值并非加倍而是+1,例如2与2合并后的数值为3. Input 输入的第一行是一个数字n,代表地图大小.然后n行,i+1行代表第i个数的大小 Output 输出仅一行,为最大能合并出的大小 Hint 1<=n<=248,不保证所有的数字能被合成完 Sample Input Sample Output solution 典型的区间DP.首先考虑区间dp最…
题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small touch screen rather cumbersome to use with her large hooves. She is particularly intrigued by the current game she is playing.The game starts with a seq…
[USACO16OPEN]248 G 题目: 题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small touch screen rather cumbersome to use with her large hooves. She is particularly intrigued by the current game she is playing.The…
https://www.luogu.org/problemnew/show/P3147 此题与上一题完全一样,唯一不一样的就是数据范围; 上一题是248,而这一题是262144; 普通的区间dp表示状态表示法根本存不下, 这时我们就要想另外的状态表示法; #include <bits/stdc++.h> #define read read() #define up(i,l,r) for(int i = (l);i <=(r); i++) using namespace std; int…
P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small touch screen rather cumbersome to use with her large hooves. She is particularly intrigued by the current game she is playing.…
4380: [POI2015]Myjnie Time Limit: 40 Sec  Memory Limit: 256 MBSec  Special JudgeSubmit: 162  Solved: 82[Submit][Status][Discuss] Description 有n家洗车店从左往右排成一排,每家店都有一个正整数价格p[i].有m个人要来消费,第i个人会驶过第a[i]个开始一直到第b[i]个洗车店,且会选择这些店中最便宜的一个进行一次消费.但是如果这个最便宜的价格大于c[i],…
Blocks Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5252   Accepted: 2165 Description Some of you may have played a game called 'Blocks'. There are n blocks in a row, each box has a color. Here is an example: Gold, Silver, Silver, Sil…
http://lightoj.com/volume_showproblem.php?problem=1422 做的第一道区间DP的题目,试水. 参考解题报告: http://www.cnblogs.com/ziyi--caolu/p/3236035.html http://blog.csdn.net/hcbbt/article/details/15478095 dp[i][j]为第i天到第j天要穿的最少衣服,考虑第i天,如果后面的[i+1, j]天的衣服不要管,那么dp[i][j] = dp[i…
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1588  Solved: 925[Submit][Status][Discuss] Description 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后 他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使得自己的名字能够扩充得很长. 现在,他想请你猜猜某一个很长的名字,最初可能…
题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2+dp[i+1][k-1]+dp[k+1][j] ); 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #def…
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5900 Description Every school has some legends, Northeastern University is the same. Enter from the north gate of Northeastern University,You are facing the main building of Northeastern University.…
题意: 给一段字符串成段染色,问染成目标串最少次数. SOL: 区间DP... DP[i][j]表示从i染到j最小代价 转移:dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k+1][j]); CODE: BZ: /*================================================================= # Created time: 2016-03-28 21:10 # Filename: uva4394.cpp # Desc…
前言:这两天没有写什么题目,把前两周做的有些意思的背包题和最长递增.公共子序列写了个总结.反过去写总结,总能让自己有一番收获......就区间dp来说,一开始我完全不明白它是怎么应用的,甚至于看解题报告都看不明白,而到了现在,遇到区间dp之类的题目,我不至于没有任何方向,慢慢的推导,有些题目没有自己想象的那么难,还是可以推导出转移方程的,有些题目,在自己推导过后,与解题报告相对照,也总能有一番全新的收获.我是觉得,解题报告需要看,但是怎么看,如何看,却是值得思量....... 1.Light o…
经典博弈区间DP 题目链接:https://uva.onlinejudge.org/external/108/p10891.pdf 题意: 给定n个数字,A和B可以从这串数字的两端任意选数字,一次只能从一端选取. 并且A B都尽力使自己选择的结果为最大的,可以理解成A B每一步走的都是最优的. 如果A先选择,则A B差值最大是多少. 分析: 总和是一定的,所以一个得分越高,另一个人的得分越低.当前状态总是最开始的状态的一个子状态. d(i,j): 先手取 i ~ j 最优策略下,得分最大值. d…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5900 Problem Description Every school has some legends, Northeastern University is the same. Enter from the north gate of Northeastern University,You are facing the main building of Northeastern Universi…
题目链接 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2988 problem Description Flatland government is building a new highway that will be used to transport weapons from its main weapon plan…
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4283 Problem Description The TV shows such as You Are the One has been very popular. In order to meet the need of boys who are still single, TJUT hold the show itself. The show is hold in the Small…
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=4293 Problem Description After the regional contest, all the ACMers are walking alone a very long avenue to the dining hall in groups. Groups can vary in size for kinds of reasons, which means, sev…
题目链接 http://poj.org/problem?id=1141 Description Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular sequence. 2. If S is a regular sequence, then (S) and [S] are both regular sequences. 3. If A and B are reg…
题目链接 http://lightoj.com/volume_showproblem.php?problem=1031 Description You are playing a two player game. Initially there are n integer numbers in an array and player A and B get chance to take them alternatively. Each player can take one or more nu…
题目链接 http://acm.split.hdu.edu.cn/showproblem.php?pid=5396 Problem Description Teacher Mai has n numbers a1,a2,⋯,anand n−1 operators("+", "-" or "*")op1,op2,⋯,opn−1, which are arranged in the form a1 op1 a2 op2 a3 ⋯ an. He wan…
题意:给括号匹配涂色,红色蓝色或不涂,要求见原题,求方案数 区间DP 用栈先处理匹配 f[i][j][0/1/2][0/1/2]表示i到ji涂色和j涂色的方案数 l和r匹配的话,转移到(l+1,r-1) 不匹配,i的匹配p一定在l和r之间,从p分开转移 听说用记忆化搜索比较快,可以像树形DP那样写记忆化搜索,也可以传统的四个参数那样写 用循环+条件判断,简化状态转移的枚举 注意细节 见代码 #include<iostream> #include<cstdio> #include&l…
Brackets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5424   Accepted: 2909 Description We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, if s is a regular…
1090: [SCOI2003]字符串折叠 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1127  Solved: 737[Submit][Status][Discuss] Description 折叠的定义如下: 1. 一个字符串可以看成它自身的折叠.记作S  S 2. X(S)是X(X>1)个S连接在一起的串的折叠.记作X(S)  SSSS…S(X个S). 3. 如果A  A’, BB’,则AB  A’B’ 例如,因为3(A) =…
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1560  Solved: 907[Submit][Status][Discuss] Description 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使得自己的名字能够扩充得很长.现在,他想请你猜猜某一个很长的名字,最初可能是由…