ZOJ-3725 Painting Storages DP】的更多相关文章

Painting Storages Time Limit: 2 Seconds      Memory Limit: 65536 KB There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to paint all storages with two colors: red and blue. Each storage will be painted with e…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5048 Sample Input 4 3 Sample Output 3 题目大意:n个格子排成一条直线,可以选择涂成红色或蓝色,问最少 m 个连续为红色的方案数. 分析:递推法 dp[i] 表示前 i 个最少 m 个连续为红色的方案数. 转移时,分类讨论: 1.前 i-1 个已经满足这个性质,那么,第 i 个随意涂色,方案数为 dp[i-1] * 2 . 2.前 i…
Description There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to paint all storages with two colors: red and blue. Each storage will be painted with exactly one color. Bob has a requirement: there are at le…
题目要求找到至少存在m个连续被染成红色的情况,相对应的,我们求至多有m-1个连续的被染成红色的情况数目,然后用总的数目将其减去是更容易的做法. 用dp来找满足条件的情况数目,, 状态:dp[i][0]和dp[i][1]分别表示第i个柱子被染成红色和蓝色的情况数目. 状态转移:dp[i][0] = dp[i-1][0]+dp[i][1]-dp[i-m][1];                     dp[i][1] = dp[i-1][0]+dp[i][1]; 代码如下: #include <c…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3725 n个点排列,给每个点着色,求其中至少有m个红色的点连续的数目.f[i]表示前i个点至少有m个连续红色的个数,则f[i]=f[i-1]*2+2^(i-m-1)-f[i-m-1]. //STATUS:C++_AC_120MS_1784KB #include <functional> #include <algorithm> #include &l…
ZOJ Problem Set - 3822Domination(DP) problemCode=3822">题目链接 题目大意: 给你一个n * m的棋盘,每天都在棋盘上面放一颗棋子.直到这个棋盘上的每行每列都有至少有一颗棋子.求要用的天数的期望. 解题思路:         先求出不同摆法的棋盘的概率,然后在和天数相乘就是期望.         我们将棋盘划分为四个部分:当中一部分为每行没列都至少有一个棋子.         然后得出状态转移方程:         dp[x][y][k…
There is a straight highway with N storages alongside it labeled by 1,2,3,...,N. Bob asks you to paint all storages with two colors: red and blue. Each storage will be painted with exactly one color. Bob has a requirement: there are at least M contin…
题意: n个格子排成一条直线,可以选择涂成红色或蓝色,问最少 m 个连续为红色的方案数. 解题思路: 应该是这次 ZOJ 月赛最水的一题,可惜还是没想到... dp[i] 表示前 i 个最少 m 个连续为红色的方案数. 转移时,分类讨论: 1.前 i-1 个已经满足这个性质,那么,第 i 个随意涂色,方案数为 dp[i-1] * 2 . 2.前 i-1 个不满足这个性质,那么,要想成为方案,区间 [i-m+1,i] 必须涂成红色.并且,下标为 i-m 这个点必须是蓝色,否则就与 情况1 重复了.…
题意:切一个凸边行,如果不是凸包直接输出.然后输出最小代价的切割费用,把凸包都切割成三角形. 先判断是否是凸包,然后用三角形优化. dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]+w[i][k]+w[j][k]); w[i][j]代表i到j点的切割费用. dp[i][j]:表示以i到j点的最小费用.则可把凸边行分成三个部分的费用.两个凸边行(i,k),(k,j)和两条边的费用(i,k),(j,k),k为枚举的三角形顶点. Zoj 3537 Cake (DP_最优三…
B - Battle Ships Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3623 Appoint description:   Description Battle Ships is a new game which is similar to Star Craft. In this game, the enemy builds a…