CodeForces 431C K-Tree
2016-01-21 21:08
295 查看
Description
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.
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: “How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?”.
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109 + 7).
Input
A single line contains three space-separated integers: n, k and d (1 ≤ n, k ≤ 100;1 ≤ d ≤ k).
Output
Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
Sample Input
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7
分析:
窝觉得另一个同学分析的很好这其实就是一个超级阶梯问题。
唯一变化的就是多了一个限制条件:必须要有权值大于等于b的边。
f[i]表示能组成重量为i的所有方案数。
多了的这个限制条件我们可以多开一维[0/1]来辅助。
f[i][0] 表示f[i][0] 的所有方案中都不含边权大于等于b的边。
f[i][1] 表示f[i][1] 的所有方案中都含有。
那么转移的时候分两种情况:
1:如果从j这条边转移过来,j边权大于等于b 则
f[i][1]=∑(f[i-j][0]+f[i-j][1])(b≤j≤k)
因为肯定有边符合条件所以可以从两个地方转移过来。但这时候f[i][0] 就没有地方可以转移过来了,所以不管他了=-=
2:如果j
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.
As soon as Dima, a good friend of Lesha, found out about the tree, he immediately wondered: “How many paths of total weight n (the sum of all weights of the edges in the path) are there, starting from the root of a k-tree and also containing at least one edge of weight at least d?”.
Help Dima find an answer to his question. As the number of ways can be rather large, print it modulo 1000000007 (109 + 7).
Input
A single line contains three space-separated integers: n, k and d (1 ≤ n, k ≤ 100;1 ≤ d ≤ k).
Output
Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
Sample Input
Input
3 3 2
Output
3
Input
3 3 3
Output
1
Input
4 3 2
Output
6
Input
4 5 2
Output
7
分析:
窝觉得另一个同学分析的很好这其实就是一个超级阶梯问题。
唯一变化的就是多了一个限制条件:必须要有权值大于等于b的边。
f[i]表示能组成重量为i的所有方案数。
多了的这个限制条件我们可以多开一维[0/1]来辅助。
f[i][0] 表示f[i][0] 的所有方案中都不含边权大于等于b的边。
f[i][1] 表示f[i][1] 的所有方案中都含有。
那么转移的时候分两种情况:
1:如果从j这条边转移过来,j边权大于等于b 则
f[i][1]=∑(f[i-j][0]+f[i-j][1])(b≤j≤k)
因为肯定有边符合条件所以可以从两个地方转移过来。但这时候f[i][0] 就没有地方可以转移过来了,所以不管他了=-=
2:如果j
// Created by ZYD in 2015. // Copyright (c) 2015 ZYD. All rights reserved. // #include <cstdio> #include <cstdlib> #include <iostream> #include <algorithm> #include <cstring> #include <climits> #include <string> #include <vector> #include <cmath> #include <stack> #include <queue> #include <set> #include <map> using namespace std; // #define mo 1e9+7 const int mo=1e9+7; #define ll long long #define mk make_pair #define pb push_back #define mem(array) memset(array,0,sizeof(array)) typedef pair<int,int> P; int n,k,d; long long dp[105][2]; int main() { freopen("in.txt","r",stdin); scanf("%d %d %d",&n,&k,&d); dp[0][0]=1; for(int i=1;i<=n;i++) for(int j=1;j<=k;j++) if(i>=j){ if(j>=d){ dp[i][1]+=dp[i-j][0]+dp[i-j][1]; } else { dp[i][1]+=dp[i-j][1]; dp[i][0]+=dp[i-j][0]; } dp[i][1]=dp[i][1] % mo; dp[i][0]=dp[i][0] % mo; } printf("%lld\n",dp [1]); return 0; }
相关文章推荐
- note(es , 随机ip)
- C# DataTable的詳細用法
- nginx多域名配置
- HDU 1043 Eight(八数码第五境界|A*+哈希+简单估价函数+打表)
- POJ-3252-Round Numbers-组合数学-递推
- codeforces 589G:线段树+二分
- poj1459 Power Network (多源多汇最大流)
- POJ 2828 线段树单点更新 离线搞
- 3289: Mato的文件管理 莫队算法+树状数组
- maven笔记
- SIP相关协议
- PHP版本VC6与VC9/VC11/VC14、Thread Safe与None-Thread Safe等的区别
- 【React Native开发】React Native控件之Image组件讲解与美团首页顶部效果实例(10)
- unity3d编程日志
- android145 360 进程管理
- Tomcat WEB-INF\class目录下的class文件不更新问题解决办法
- 为什么一个字节等于8个比特
- 组合数公式
- IQueryable与IEnumerable区别
- bzoj3295: [Cqoi2011]动态逆序对 树状数组套线段树