CF 431C k-Tree
来源:互联网 发布:st单片机仿真器 编辑:程序博客网 时间:2024/05/20 10:23
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree.
A k-tree is an infinite rooted tree where:
- each vertex has exactly k children;
- each edge has some weight;
- if we look at the edges that goes from some vertex to its children (exactly k edges), then their weights will equal 1, 2, 3, ..., k.
The picture below shows a part of a 3-tree.
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo1000000007 (109 + 7).
A single line contains three space-separated integers: n, k and d (1 ≤ n, k ≤ 100; 1 ≤ d ≤ k).
Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
3 3 2
3
3 3 3
1
4 3 2
6
4 5 2
7
题意:
k-Tree,每个节点有k个儿子,边权分别是1、2、……、K。
现求出从根节点出发,有多少条路径,使得总权值恰好为N,并且每条路径上至少有一条权值不少于d的边。
分析:
dp[i][x]表示当到达i状态时的总数,x为0或1,0表示之前没有使用过>=d的边,1表示之前有使用过>d的边。
则有状态转移方程:
dp[i][0] += dp[i-j][0] , (j < d)
dp[i][1] += dp[i-j][0] , (j>=d)
dp[i][1] += dp[i-j][1]
初始化dp[0][0] = 1;
这题还需要注意数据的类型,不能写成INT,应该写成LONG LONG。。。。。。。。。。这会导致WA。(注意)
#include<iostream>#include<cstdio>#include<cstring>long long dp[200][2];using namespace std;long long mod = 1000000007;int main(){long long n,k,d;while(~scanf("%I64d%I64d%I64d",&n,&k,&d)){memset(dp,0,sizeof(dp));dp[0][0] = 1;for(int i=1;i<=n;i++){for(int j=1;j<=k;j++){if(j<d&&i-j>=0){dp[i][0] += dp[i-j][0];dp[i][1] += dp[i-j][1];}else if(j>=d&&i-j>=0){dp[i][1] += dp[i-j][0];dp[i][1] += dp[i-j][1];}dp[i][0] = dp[i][0]%mod;dp[i][1] = dp[i][1]%mod;}}cout<<dp[n][1]<<endl;}return 0;}
- CF 431C k-Tree
- CF 431 C k-Tree(有序完全背包)
- Codefoces 431 C. k-Tree
- CodeForces 431C K-Tree
- CodeForces 431C k-Tree
- CF 109C: Lucky Tree
- CodeForces 431C k-Tree(dp)
- codeforces-431C-k-Tree【dp】
- Codeforces 431C k-Tree (基础dp)
- Codeforces 431C k-Tree【dp】
- Codeforces 431C k-Tree 题解
- C. k-Tree
- CF 275C- k-Multiple Free Set
- cf#342-C - K-special Tables-构造
- Codeforces 431C —— k-Tree(DP)
- Codeforces 431C k-tree DP(拆分数)
- Codeforces 431C —— k-Tree(DP)
- cf 625 C. K-special Tables (打表+规律)
- error C2664
- HDU 2108 Shape of HDU(判断凸凹变形 叉积)
- 点击Gallery弹出对应的Gallery大图
- TCP洪水攻击(SYN Flood)的诊断和处理
- C++ vector多维数组初始化及清零
- CF 431C k-Tree
- 2【学校教学系统】登录API嗅探和模仿浏览器登录
- Excel Sheet Column Number
- 登录界面保存信息
- undefined reference to `__udivdi3'
- JDK的配置及出现问题的解决方案
- 安卓三种动画小结
- html中的js获取当前的页面是位于哪个容器中打开(pc,手机,微信...)
- 黑马程序员--线程间的通信