CF9D How many trees? (dp)】的更多相关文章

这题我想了好久 设 \(f_{i,j}\) 为 \(i\) 结点 \(<=j\) 的方案数 固定根,枚举左右子树,就有: \[f_{i,j}=\sum_{k=0}^{n-1}f_{k,j-1}*f_{i-k-1,j-1}\] 初始化 \(f_{0,i}=1\) 答案 \(ans=f_{n,n}-f_{n,h-1}\) Code #include<algorithm> #include<iostream> #include<cstring> #include<…
C. Coloring Trees   ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right…
题目链接:C. Coloring Trees 题意:给出n棵树的颜色,有些树被染了,有些没有.现在让你把没被染色的树染色.使得beauty = k.问,最少使用的颜料是多少.   K:连续的颜色为一组,一共有多少组. 颜料用量:p[i][j]表示第i棵树用颜料j染色 需要p[i][j]颜料. 思路:DP. dp方程:dp[i][j][k] = a 表示前i棵树beauty = j,且第j棵树染色为k时,需要的最少颜料为a. 状态转移:初始化第一棵树dp[1][1][col[1]or(1~m)].…
传送门:http://codeforces.com/problemset/problem/711/C 题目: C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder and Chris the Baboon has arrived at Udayland! They wal…
题目链接: C. Coloring Trees time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided…
Trees  Accepts: 156  Submissions: 533  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Others) Problem Description Today CodeFamer is going to cut trees.There are N trees standing in a line. They are numbered from 1 to N. Th…
D. How many trees? time limit per test 1 second memory limit per test 64 megabytes input standard input output standard output In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phon…
C. Coloring Trees time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be…
D. How many trees? 题目连接: http://www.codeforces.com/contest/9/problem/D Description In one very old text file there was written Great Wisdom. This Wisdom was so Great that nobody could decipher it, even Phong - the oldest among the inhabitants of Main…
题目链接 以前做过类似的,USACO,2.3,开始数组开小了,导致数据乱了,然后超数据范围了,.. #include <cstdio> #include <iostream> #include <cmath> using namespace std; #define LL __int64 LL dp[][][]; LL c[][]; int main() { int i,j,n,k,u,h; ; i <= ; i ++) { c[i][] = ; } ; i &l…