http://codeforces.com/problemset/problem/659/G 思路: f(i,0/1,0/1) 表示到了第i个,要被切的块开始了没有,结束了没有的状态的方案数 递推看代码: //File Name: cf659G.cpp //Author: long //Mail: 736726758@qq.com //Created Time: 2016年07月12日 星期二 12时40分28秒 #include <stdio.h> #include <string.h…
题目链接: G. Fence Divercity time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecu…
G. Fence Divercity 题目连接: http://www.codeforces.com/contest/659/problem/G Description Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter widt…
题目链接:http://codeforces.com/contest/1221/problem/D 题目要求ai ! = ai-1,草纸上推理一下可以发现每一个栅栏可以升高的高度无非就是 +0,+1,+2 用dp[i][j]表示到第 i 个栅栏升高 j 高度时,所需要的最小花费. 状态转移方程:dp[i][j] = min(dp[i-1][k]+j*b[i],dp[i][j]),其实每次循环共枚举了9次,分别是第 i 个栅栏升高 j 高度时候,对前一个也就是第i-1个栅栏分别升高+0,+1,+2…
Fence Divercity 我们设a[ i ] 为第 i 个围栏被切的最靠下的位置, 我们发现a[ i ] 的最大取值有一下信息: 如果从i - 1过来并在 i  结束a[ i ] = min(h[ i - 1], h[ i ]) 如果从i - 1过来并延续到i + 1,   a[ i ] = min(h[ i - 1 ], h[ i ], h[ i + 1 ]) 如果从 i 开始 i 结束 a[ i ] = h[ i ] 如果从 i 开始并延续到 i + 1,   a[ i ] = min…
题目链接:Codeforces 461B Appleman and Tree 题目大意:一棵树,以0节点为根节点,给定每一个节点的父亲节点,以及每一个点的颜色(0表示白色,1表示黑色),切断这棵树的k条边,使得树变成k+1个联通分量.保证每一个联通分量有且仅有1个黑色节点.问有多少种切割方法. 解题思路:树形dp,dp[i][0]和dp[i][1]分别表示子树一下的切割方法中,i节点所在联通块不存在黑节点和已经存在一个黑节点的方案数. #include <cstdio> #include &l…
[CodeForces - 1225E]Rock Is Push [dp][前缀和] 标签:题解 codeforces题解 dp 前缀和 题目描述 Time limit 2000 ms Memory limit 524288 kB Source Technocup 2020 - Elimination Round 2 Tags binary search dp *2200 Site https://codeforces.com/problemset/problem/1225/E 题面 Examp…
[codeforces 549]G. Happy Line 试题描述 Do you like summer? Residents of Berland do. They especially love eating ice cream in the hot summer. So this summer day a large queue of n Berland residents lined up in front of the ice cream stall. We know that ea…
CodeForces 794 G.Replace All 解题思路 首先如果字符串 \(A, B\) 没有匹配,那么二元组 \((S, T)\) 合法的一个必要条件是存在正整数对 \((x,y)\),使得 \(xS=yT\),其中 \(xS\) 是将字符串 \(S\) 复制 \(x\) 遍后得到的字符串,\(yT\) 是将字符串 \(T\) 复制 \(T\) 遍后得到的字符串.由于 \(A,B\) 直接匹配的情况比较容易讨论,下面没有特殊说明,都是 \(A,B\) 没有直接匹配的情况. 这个条件…
题目描述 给你一个长度为 $n$ 的序列 $\{a_i\}$ 和一个数 $x$ ,对于任意一个 $1\sim n$ 的排列 $\{p_i\}$ ,从 $1$ 到 $n$ 依次执行 $x=x\ \text{mod}\ a_{p_i}$ ,最终得到一个数.求所有排列中能够得到的这个数的最大值,以及有多少种排列可以得到这个值. $n\le 1000$ ,$x\le 5000$ . 题解 组合数学+dp 由于 $a\ \text{mod}\ b<b$ ,因此每次产生影响(即 $x\ \text{mod}…