Codeforces 1076F Summer Practice Report dp】的更多相关文章

Summer Practice Report dp[ i ][ 0 ]表示放完前 i 页, 第 i 页最后一段是 0, 0个数的最小值. dp[ i ][ 1 ]表示放完前 i 页, 第 i 页最后一段是 1, 1个数的最小值. 这个转移细节有点多... #include<bits/stdc++.h> #define LL long long #define LD long double #define fi first #define se second #define mk make_pa…
题目链接:传送门 题目: F. Summer Practice Report time limit per test seconds memory limit per test megabytes input standard input output standard output Vova has taken his summer practice this year and now he should write a report on how it went. Vova has alre…
[BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权值为i的二叉树的个数. 两棵树不同当且仅当树的形态不一样或者是树的某个点的点权不一样 分析 设\(c(i)\)表示数值i是否在集合中.\(f(i)\)表示权值为i的二叉树的个数.那么 \[f(n)=\sum_{i=1}^n c(i) \sum_{j=0}^{n-i} f(j)f(n-i-j)\] 其…
题目链接:http://codeforces.com/contest/721/problem/C 题意:从1走到n,问在时间T内最多经过多少个点,按路径顺序输出. 思路:比赛的时候只想到拓排然后就不知道怎么办了......先拓扑排序,再按照拓扑的顺序进行DP,dp[to][j](到i点走过j个点最短时间) = min(dp[to][j], dp[i][j] + dis) #include<bits/stdc++.h> using namespace std; typedef long long…
题目链接:http://codeforces.com/problemset/problem/711/C O(n^4)的复杂度,以为会超时的 思路:dp[i][j][k]表示第i棵数用颜色k涂完后beauty为j #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll inf=1e15; int c[105]; int p[105][105]; ll dp[105][105][105]; int ma…
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer number is beautiful if…
题目链接:http://codeforces.com/contest/543/problem/D 给你一棵树,初始所有的边都是坏的,要你修复若干边.指定一个root,所有的点到root最多只有一个坏边.以每个点为root,问分别有多少种方案数. dp[i]表示以i为子树的root的情况数,不考虑父节点,考虑子节点.   dp[i] = dp[i] * (dp[i->son] + 1) up[i]表示以i为子树的root的情况数(倒着的),考虑父节点,不考虑子节点.  这里需要逆元. 注意(a/b…
题目链接:http://codeforces.com/contest/467/problem/C 求k个不重叠长m的连续子序列的最大和. dp[i][j]表示第i个数的位置个序列的最大和. 前缀和一下就好了.空间可以优化,滚动数组就好了. //#pragma comment(linker, "/STACK:102400000, 102400000") #include <algorithm> #include <iostream> #include <cs…
题目链接:http://codeforces.com/problemset/problem/711/C 给你n棵树,m种颜色,k是指定最后的完美值.接下来一行n个数 表示1~n树原本的颜色,0的话就是没颜色(一定要上色),非0就是有颜色(不能上色). 接下来n行 每行m个数,第i行第j个数表示 编号为i的树上第j种颜色的代价为a[i][j]. 问你最后要使完美值为k的上色代价最小为多少,要是不可能的话就为-1. 我们来考虑dp,每个树和前一个树有联系. dp[i][j][x] 表示第i棵树 完美…
题目链接:http://codeforces.com/problemset/problem/706/C 给你n个字符串,可以反转任意一个字符串,反转每个字符串都有其对应的花费ci. 经过操作后是否能满足字符串str[i]>=str[i-1],能就输出最小花费,不能输出-1. dp[i][0] 表示不反转i的最小花费(str[i] >= str[i - 1] || str[i] >= reverse(str[i - 1])) dp[i][1] 则表示反转i的最小花费... 初始dp[1][…