码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #247 (Div. 2) C. k-Tree

时间:2015-10-23 22:40:39      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:

题目链接:http://codeforces.com/problemset/problem/431/C

题意:给一个k-tree,每个节点有k个儿子,然后边权从左到右依次为1-k,给定n, k, d, 求至少有一条边权值>=d然后总和是n有多少种方法

题解:dp[i][j][0]表示当前到第i层,和为j,没有超过d的边权的方法数,dp[i][j][1]表示当前到第i层,和为j,有超过d的边权的方法数。

 

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cmath>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;
LL dp[101][101][2];
int main()
{
    int n, k, d;
    cin >> n >> k >> d;
    dp[0][0][0] = 1;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)  {
            for(int x = 1; x < d && x+j <= n; x++)  dp[i+1][j+x][0] = (dp[i+1][j+x][0]+dp[i][j][0])%mod;
            for(int x = 1; x <= k && x+j <= n; x++)
                if(x < d)  dp[i+1][j+x][1] = (dp[i+1][j+x][1]+dp[i][j][1])%mod;
                else  dp[i+1][j+x][1] = (dp[i+1][j+x][1]+dp[i][j][1]+dp[i][j][0])%mod;
        }
    int ans = 0;
    for(int i = 1; i <= n; i++)  ans = (ans+dp[i][n][1])%mod;
    cout << ans << endl;
}

Codeforces Round #247 (Div. 2) C. k-Tree

标签:

原文地址:http://www.cnblogs.com/sswzfly/p/4905729.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!