RPG的错排 Time Limit: 2000/1000ms (Java/Others) Problem Description: 今年暑假GOJ集训队第一次组成女生队,其中有一队叫RPG,但做为集训队成员之一的野骆驼竟然不知道RPG三个人具体是谁谁.RPG给他机会让他猜猜,第一次猜:R是公主,P是草儿,G是月野兔:第二次猜:R是草儿,P是月野兔,G是公主:第三次猜:R是草儿,P是公主,G是月野兔:......可怜的野骆驼第六次终于把RPG分清楚了.由于RPG的带动,做ACM的女生越来越多,我们…
题目传送门 题意:k个马棚,n条马,黑马1, 白马0,每个马棚unhappy指数:黑马数*白马数,问最小的unhappy值是多少分析:dp[i][j] 表示第i个马棚放j只马的最小unhappy值,状态转移方程:dp[i][j] = min (dp[i][j], dp[i-1][k-1] + cur * (j - k + 1 - cur)); 表示k到j匹马放在第i个马棚的最小unhappy值,dp[0][0] = 0.由于黑马数是1的和,前缀sum[i]表示前i匹马黑马的个数,白马就是总个数-…
题目传送门 /* 题意:给n块砖头,问能组成多少个楼梯,楼梯至少两层,且每层至少一块砖头,层与层之间数目不能相等! 递推DP:dp[i][j] 表示总共i块砖头,最后一列的砖头数是j块的方案数 状态转移方程:dp[i][j] += dp[i-j][k] 表示最后一列是j,那么上一个状态是少了最后一列 总共i-j块砖头,倒数第二列是k块砖头.k<j, j<=i 最后累加dp[n][i], i<n因为最少要两层 dp[0][0] = 1; 还有更简单的做法,没看懂:http://m.blog…
题目传送门 /* 递推DP: dp[i] 表示放i的方案数,最后累加前n-2的数字的方案数 */ #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> using namespace std; ; const int INF = 0x3f3f3f3f; ]; int main(void) //URAL 1260 Nudnik Photographer { //fr…
题目传送门 /* 题意:1~1e9的数字里,各个位数数字相加和为s的个数 递推DP:dp[i][j] 表示i位数字,当前数字和为j的个数 状态转移方程:dp[i][j] += dp[i-1][j-k],为了不出现负数 改为:dp[i][j+k] += dp[i-1][j] */ #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <str…
题目传送门 /* 题意:已知起点(1,1),终点(n,m):从一个点水平或垂直走到相邻的点距离+1,还有k个抄近道的对角线+sqrt (2.0): 递推DP:仿照JayYe,处理的很巧妙,学习:) 好像还要滚动数组,不会,以后再补 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cmath> #include <cstring> using names…
题目传送门 /* 递推DP:官方题解 令Fi,j代表剩下i个人时,若BrotherK的位置是1,那么位置为j的人是否可能获胜 转移的时候可以枚举当前轮指定的数是什么,那么就可以计算出当前位置j的人在剩下i − 1个人时的位置 (假设BrotherK所处的位置是1),然后利用之前计算出的F值判定此人是否可能获胜 时间复杂度为O(n3) dp[i][j] 表示有i个人,j位置的人是否可能胜利.dp[1][0] = 1; cnt = sum (dp[n][i]); 有最优化子结构,i个人可以由i-1个…
题目传送门 /* 递推DP: 如果a, b, c是等差数列,且b, c, d是等差数列,那么a, b, c, d是等差数列,等比数列同理 判断ai-2, ai-1, ai是否是等差(比)数列,能在O(n)时间求出最长的长度 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1978 分析: 递推DP. dp[][]表示可以到达改点的方法数. 刚开始:外循环扫描所有点dp[x][y],而内循环扫描出所有可以到达点x.y的点i.j.那么dp[x][y]就是所有的dp[i][l]之和. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #in…
题目传送门 /* 简单递推DP:读题烦!在区间内的都更新一遍,dp[]初始化INF 注意:s1与s2大小不一定,坑! 详细解释:http://blog.csdn.net/kk303/article/details/6847948 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <string> #include &l…