Codeforces Round #247 (Div. 2)
来源:互联网 发布:渐飞数据伴侣 编辑:程序博客网 时间:2024/05/21 17:36
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 modulo 1000000007(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
和bjfuoj的Frozen口袋类似,二维dp,dp[i][j],i存到和,j==0时,表示到i为止,还没出现过>=d的数,反之,j==1时,则出现过。
记住%1e9+7。。。开了long long。
然后每层dp一下,状态转移为:
if(j>=d)
dp[i][1]=(dp[i][1]+dp[i-j][0]+dp[i-j][1])%mod
else
{
dp[i][0]=(dp[i][0]+dp[i-j][0])%mod
dp[i][1]=(dp[i][1]+dp[i-j][1])%mod
}
我们需要把dp[i][0]放在else里面,防止重复计数。
#include<cstdio>#include<cstdlib>#include<iostream>#include<stack>#include<queue>#include<algorithm>#include<string>#include<cstring>#include<cmath>#include<vector>#include<map>#include<set>#define eps 1e-8#define zero(x) (((x>0?(x):-(x))-eps)#define mem(a,b) memset(a,b,sizeof(a))#define memmax(a) memset(a,0x3f,sizeof(a))#define pfn printf("\n")#define ll __int64#define ull unsigned long long#define sf(a) scanf("%d",&a)#define sf64(a) scanf("%I64d",&a)#define sf264(a,b) scanf("%I64d%I64d",&a,&b)#define sf364(a,b,c) scanf("%I64d%I64d%I64d",&a,&b,&c)#define sf464(a,b,c,d) scanf("%I64d%I64d%I64d%I64d",&a,&b,&c,&d)#define sf564(a,b,c,d,ee) scanf("%I64d%I64d%I64d%I64d%I64d",&a,&b,&c,&d,&ee)#define sf2(a,b) scanf("%d%d",&a,&b)#define sf3(a,b,c) scanf("%d%d%d",&a,&b,&c)#define sf4(a,b,c,d) scanf("%d%d%d%d",&a,&b,&c,&d)#define sf5(a,b,c,d,ee) scanf("%d%d%d%d%d",&a,&b,&c,&d,&ee)#define sff(a) scanf("%f",&a)#define sfs(a) scanf("%s",a)#define sfs2(a,b) scanf("%s%s",a,b)#define sfs3(a,b,c) scanf("%s%s%s",a,b,c)#define sfd(a) scanf("%lf",&a)#define sfd2(a,b) scanf("%lf%lf",&a,&b)#define sfd3(a,b,c) scanf("%lf%lf%lf",&a,&b,&c)#define sfd4(a,b,c,d) scanf("%lf%lf%lf%lf",&a,&b,&c,&d)#define sfc(a) scanf("%c",&a)#define ull unsigned long long#define pp pair<int,int>#define debug printf("***\n")#define pi 3.1415927#define mod 1000000007#define rep(i,a,b) for(int i=a;i<b;i++)const double PI = acos(-1.0);const double e = exp(1.0);const int INF = 0x7fffffff;;template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }template<class T> inline T Min(T a, T b) { return a < b ? a : b; }template<class T> inline T Max(T a, T b) { return a > b ? a : b; }bool cmpbig(int a, int b){ return a>b; }bool cmpsmall(int a, int b){ return a<b; }using namespace std;int main(){ //freopen("data.in","r",stdin); //freopen("data.out" ,"w",stdout); int n,k,d; while(~sf3(n,k,d)) { ll dp[110][2]; mem(dp,0); dp[0][0]=1; for(int i=1;i<=n;i++) { for(int j=1;j<=min(k,i);j++) { if(j>=d) dp[i][1]=(dp[i][1]+dp[i-j][0]+dp[i-j][1])%mod; else { dp[i][1]=(dp[i][1]+dp[i-j][1])%mod; dp[i][0]=(dp[i][0]+dp[i-j][0])%mod; } } } printf("%d\n",dp[n][1]%mod); } return 0;}
- Codeforces Round #247 (Div. 2)
- Codeforces Round #247 (Div. 2)
- Codeforces Round #247 (Div. 2)
- Codeforces Round #247 (Div. 2) A B
- Codeforces Round #247 (Div. 2) ABC
- Codeforces round #247 for Div. 2
- Codeforces Round #247 (Div. 2) B
- Codeforces Round #247 (Div. 2) 总结
- Codeforces Round #102 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #103 (Div. 2)
- Codeforces Round #104 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #105 (Div. 2)
- Codeforces Round #107 (Div. 2)
- Codeforces Round #108 (Div. 2)
- Codeforces Round #110 (Div. 2)
- Codeforces Round #122 (Div. 2)
- Android AndroidManifest.xml相关flag详细说明
- myeclipse+pydev4.0.1+scrapy 构建爬虫项目的流程
- 数据结构--链表
- 506. Relative Ranks的C++解法
- astgo-官方提供的使用技巧大全
- Codeforces Round #247 (Div. 2)
- ZOJ 3949 Edge to the Root(树形DP)
- Jquery加密密码到cookie
- Maven下解决中文乱码
- webpack入门(四)
- fprintf函数的的用法
- day4:纸质笔记完结
- 个人对面试者和面试官的几点经验总结
- Unity之射线穿透