[USACO16OPEN]248 G——区间dp】的更多相关文章

[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 gam…
传送门 f[i][j]表示区间 i-j 合并的最大值 转移: 若f[i][k] && f[k+1][j] && f[i][k] == f[k+1][j] --> f[i][j] = max(f[i][k]+1,f[i][j]) 但要注意, 若f[i][k]!=f[k+1][j],那么无法进行转移 代码 #include <cstdio> #include <iostream> #define max(x, y) ((x) > (y) ?…
[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…
题目描述 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…
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.…
记录一些基础的区间 \(\text{DP}\) 题. 0x00 AT_dp_n N - Slimes 最板的区间 \(\text{DP}\) . 记 \(f[i][j]\) 表示合并 \(i\sim j\) 区间的最小代价,初始化为 \(\text{inf}\),\(f[i][i]=0\) (一个数不需要代价). 第一维从小到大枚举区间长度 \(len\),第二维枚举左端点 \(i\),同时可以计算出右端点 \(j=i+len-1\),第三维枚举段点 \(k\),转移方程为 \[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…
题目描述 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…
题目描述 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…
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…
传送门 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最…
P3146 [USACO16OPEN]248 题目描述 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…
P3146 [USACO16OPEN]248 题目描述 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…
P3146 [USACO16OPEN]248 题解 第一道自己码出的区间DP快庆祝一哈 2048 每次可以合并任意相邻的两个数字,得到的不是翻倍而是+1 dp[L][R] 区间 L~R 合并结果 然后拆成左区间和右区间,看看他们能不能合并,更新ans 注意如果最后枚举到的总区间 1~n ,那么就要考虑取左右区间最大值了,因为可能左右区间不能合并,那么左右区间最大值就是最终答案 代码 #include<iostream> #include<cstdio> #include<st…
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…
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1588  Solved: 925[Submit][Status][Discuss] Description 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后 他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使得自己的名字能够扩充得很长. 现在,他想请你猜猜某一个很长的名字,最初可能…
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1560  Solved: 907[Submit][Status][Discuss] Description 某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使得自己的名字能够扩充得很长.现在,他想请你猜猜某一个很长的名字,最初可能是由…
        ID Origin Title   17 / 60 Problem A ZOJ 3537 Cake   54 / 105 Problem B LightOJ 1422 Halloween Costumes   59 / 90 Problem C POJ 2955 Brackets   26 / 51 Problem D CodeForces 149D Coloring Brackets   47 / 58 Problem E POJ 1651 Multiplication Puz…
区间DP是一类在区间上进行dp的最优问题,一般是根据问题设出一个表示状态的dp,可以是二维的也可以是三维的,一般情况下为二维. 然后将问题划分成两个子问题,也就是一段区间分成左右两个区间,然后将左右两个区间合并到整个区间,或者说局部最优解合并为全局最优解,然后得解. 区间dp就是f[i][j]表示i到j的一段区间, 然后去转移最优值的dp 一段区间表示一段状态,维护i~j的最优值来转移. 常见区间dp有:合并石子,破环成链类题目 其实对于环形区间DP有一个对付环的好方法:关于N取模(特殊处理0)…
1055: [HAOI2008]玩具取名 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1258  Solved: 729[Submit][Status][Discuss] Description 某 人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用 “WING”中任意两个字母代替,使得自己的名字能够扩充得很长.现在,他想请你猜猜某一个很长的名字,最初可能…
Description Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning to attend as many parties as he can. Since it's Halloween, these parties are all costume parties, Gappu always selects his costumes in such…
D - Fox And Jumping Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 512B Description Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integer…
Time Limit: 1000 ms   Memory Limit: 256 MB Description 大家都知道,长城在自然条件下会被侵蚀,因此,我们需要修复.现在是21世纪,修复长城的事情当然就交给机器人来干辣.我们知道,长城每时每刻都在受到侵蚀,如果现在不修复,以后修复的代价会更高.现在,请你写一个程序来确定机器人修长城的顺序,使得修复长城的代价最小. 在这道题中,我们认为长城是一条很长的线段,长城的每个位置都有唯一的数字与它对应(即当前位置到长城某一端的距离).这台机器人开始被放在…
题目: https://www.lydsy.com/JudgeOnline/problem.php?id=1996 题解: 这题刚拿到手的时候一脸懵逼qwq,经过思考与分析(看题解),发现是一道区间dp 首先我们考虑最终数列的形成过程,可以看做是由一个序列向左右不断加数形成的,因此,就有一个很美妙的性质:对于最终序列的任意一段,最后加入的一定是左端点或者右端点(很显然).因此我们就考虑到了区间dp.. 最终序列为g,定义dp[i][j][k](k==0||k==1)表示对于最终序列的i-j区间,…
BZOJ 显然是个区间DP.令\(f[l][r]\)表示全部消掉区间\([l,r]\)的最小花费. 因为是可以通过删掉若干子串来删子序列的,所以并不好直接转移.而花费只与最大最小值有关,所以再令\(g[l][r][j][k]\)表示将区间\([l,r]\)中的数删到只剩下权值在\([j,k]\)中的数的最小花费(也就是让剩下数的最小值为\(j\),最大值为\(k\),最后一次取走\([j,k]\)这些数来删掉整个\([l,r]\)).为了方便转移强制右端点\(r\)保留,同整个区间最后一起删掉.…
传送门 原Word文档 题意:太长不给 这种题目一看就是区间DP 设$f_i$表示治愈了前$i$个村子的时候最少死了多少村民,又设前缀和为$sum_i$,通过枚举折返时最后经过的村子$j$,并且提前计算$i+1$到$N$中死的村民数量,可以得到这样子的方程:$$f_i=\min\limits_{j=1}^i\{f_{j-1}+g_{j,i}+(sum_N-sum_i) \times ((i-j) \times 3 + (i-j+1) + 1)\}$$其中$g_{j,i}$表示从$j$到$i$到$…
A - Cake 题目大意:给你一个n个顶点(n<=100)的多边形和每两个点连边的消耗,让你求把这个多边形全部切成三角形所需要的最小消耗,如果这个多边形为凹多边形则输出无解. 思路:先求一个凸包,看凸包里的点是不是n个,不是n个输出无解,求完凸包之后,点都是按顺时针排的,我们用dp[ i ][ j ]表示,i 到 j 的折线和 i 连 j的直线围成的多边形 的最小消耗. 状态转移方程:dp[ i ][ j ]=min( dp[ i ][ j ] , dp[ i ][ k ]+dp[ k ][…
题目链接 \(Description\) \(Solution\) 合法的子序列只有三种情况:递增,递减,前半部分递增然后一直递减(下去了就不会再上去了)(当然还要都满足\(|a_{i+1}-a_i|=1\)). 容易想到区间DP.\(f[i][j]\)表示把区间\([i,j]\)全部删除的最大收益,还需要\(g[i][j]\)表示将区间\([i,j]\)删成连续上升的一段(\(a_i\sim a_j\))的最大收益,\(h[i][j]\)表示将区间\([i,j]\)删成连续下降的一段(\(a_…
区间 \(dp\) 1.[HAOI2008]玩具取名 \(f[l][r][W/I/N/G]\) 表示区间 \([l,r]\) 中能否压缩成 \(W/I/N/G\) \(Code\ Below:\) #include <bits/stdc++.h> using namespace std; const int maxn=200+10; int n,W,I,N,G,le[maxn],fir[maxn],sec[maxn],f[maxn][maxn][4],cnt; char s[maxn]; in…
1719: [Usaco2006 Jan] Roping the Field 麦田巨画 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 82  Solved: 26[Submit][Status][Discuss] Description Farmer John is quite the nature artist: he often constructs large works of art on his farm. Today, FJ wants…