Codeforces Round #247(Div. 2) C. k-Tree DP
来源:互联网 发布:圣诞节淘宝海报 编辑:程序博客网 时间:2024/05/20 09:47
题意:
给定一个k叉树,且是无限有根树,每个节点有k个孩子,从左向右依次编号为1,2,3,...k,每条边有权值,节点连向i号孩子的边的权值为i,问:从根节点开始向下走,有多少条路径满足要求:该路径权值为n,且路径上至少有一条边的权值大于等于d。
题解:
直接求不好求,比较复杂,不过我们可以求出来所以权值为n的路径,然后再减去不符合要求的路径:该路径上所有的边的权值都小于d。
用dp做。
dp[i]:权值为i的路径的条数。
dp2[i]:权值为i的,且路径上的权值都小于d的路径条数。
答案为:dp[n]-dp2[n]
/*****************PID:431c div2*Auth:Jonariguez*****************dp[i]:权值为i的路径的条数dp2[i]:权值为i,且路径上的权值都小于d的路径条数答案:dp[n]-dp2[n]*/#define lson k*2,l,m#define rson k*2+1,m+1,r#define rep(i,s,e) for(i=(s);i<=(e);i++)#define For(j,s,e) For(j=(s);j<(e);j++)#define sc(x) scanf("%d",&x)#define In(x) scanf("%I64d",&x)#define pf(x) printf("%d",x)#define pfn(x) printf("%d\n",(x))#define Pf(x) printf("%I64d",(x))#define Pfn(x) printf("%I64d\n",(x))#define Pc printf(" ")#define PY puts("YES")#define PN puts("NO")#include <stdio.h>#include <string.h>#include <string>#include <math.h>#include <set>#include <map>#include <stack>#include <queue>#include <vector>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;typedef int Ll;Ll quick_pow(Ll a,Ll b,Ll MOD){a%=MOD;Ll res=1;while(b){if(b&1)res=(res*a)%MOD;b/=2;a=(a*a)%MOD;}return res;}const int maxn=100+10;const LL MOD=1e9+7;LL dp[maxn],dp2[maxn];int main(){ int i,j,n,k,d; while(scanf("%d%d%d",&n,&k,&d)!=EOF){ memset(dp,0,sizeof(dp)); memset(dp2,0,sizeof(dp2)); dp[0]=1; for(i=1;i<=n;i++){ for(j=1;j<=k;j++){ if(i-j>=0){ dp[i]+=dp[i-j]; dp[i]%=MOD; } } } dp2[0]=1; for(i=1;i<=n;i++){ for(j=1;j<d;j++){ if(i-j>=0){ dp2[i]+=dp2[i-j]; dp2[i]%=MOD; } } } LL res=(dp[n]-dp2[n])%MOD; if(res<0) res+=MOD; printf("%I64d\n",res); } return 0;}
0 0
- Codeforces Round #247(Div. 2) C. k-Tree DP
- Codeforces Round #247 (Div. 2) C. k-Tree
- Codeforces Round #247 (Div. 2) C.K-Tree
- Codeforces Round #247 (Div. 2) C k-Tree
- Codeforces #247 (Div. 2) C. k-Tree
- Codeforces Round #369 (Div. 2) 711C Coloring Tree (DP)
- Codeforces Round #247 (Div. 2)a.Black Square,b.Shower Line,c.k-Tree前三题
- 【DP】Codeforces Round #336 (Div. 2) C
- Codeforces Round #363 (Div. 2) C dp
- Codeforces Round #303 (Div. 2) C dp
- Codeforces Round #286 (Div. 2) C dp
- Codeforces Round #369 (Div. 2) C dp
- DP-Codeforces Round #369 Div.2-C
- Codeforces Round #376(Div. 2) C dp
- Codeforces Round #358 (Div. 2)-C. Alyona and the Tree(树形dp)
- Codeforces Round #358 (Div. 2) C Alyona and the Tree(树形DP)
- Codeforces Round #395 (Div.2) C-Timofey and a tree 树型dp
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree 树dp 统计
- iOS9 联系人 ContactFramework
- JZ2440:下载程序到板子上
- CentOS 6.3下配置软RAID(Software RAID)
- 猜数字
- Java线程池
- Codeforces Round #247(Div. 2) C. k-Tree DP
- CF 553A. Kyoya and Colored Balls 组合数学 和dp有点关系
- Windows系统下正确安装MongoDB
- C++:可变数据成员
- POJ 1077 Eight(八数码A*+IDA*)
- 【杭电-oj】-2561-第二小整数(sort快排)
- uploadify文件上传
- c++封装之对象成员基础
- 干活 spring依赖注入