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

题目链接: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;
}
时间: 2024-12-28 00:38:38

Codeforces Round #247 (Div. 2) C. k-Tree的相关文章

Codeforces Round #247 (Div. 2) ABC

Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431 代码均已投放:https://github.com/illuz/WayToACM/tree/master/CodeForces/431 A - Black Square 题目地址 题意: Jury玩别踩白块,游戏中有四个区域,Jury点每个区域要消耗ai的卡路里,给出踩白块的序列,问要消耗多少卡路里. 分析: 模拟水题.. 代码: /* * Author: illuz

Codeforces Round #247 (Div. 2)

A.水题. 遍历字符串对所给的对应数字求和即可. B.简单题. 对5个编号全排列,然后计算每种情况的高兴度,取最大值. C.dp. 设dp[n][is]表示对于k-trees边和等于n时,如果is==1表示存在边至少为d的边,如果is==0表示不存在边至少为d的边. 初始状态dp[0][0]=1. //和为n且不存在至少为d的边的状态可以由所有不存在至少为d的边加一条小于d的边转移而来. dp[n][0]=dp[n-1][0]+dp[n-2][0]+--+dp[n-(d-1)][0] //和为n

Codeforces Round #245 (Div. 1)——Guess the Tree

本文出自:http://blog.csdn.net/svitter 实验环境:Myeclipse10 + tomcat7.0 有时间会写windows和linux下的tomcat配置,现在时间有限,暂且不写了..有些东西也是没有理解透彻. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <%@ page language="java" contentType="

Codeforces Round #247 (Div. 2) B - Shower Line

模拟即可 #include <iostream> #include <vector> #include <algorithm> using namespace std; int main(){ vector<int> a(5); for(int i = 0; i < 5; ++ i) a[i] = i; int g[5][5]; for(int i = 0 ; i < 5; ++ i){ for(int j = 0 ; j < 5; ++

Codeforces Round #124 (Div. 1) C. Paint Tree(极角排序)

C. Paint Tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a tree with n vertexes and n points on a plane, no three points lie on one straight line. Your task is to paint

Codeforces Round #225 (Div. 1) C. Propagating tree dfs序+树状数组

C. Propagating tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/383/problem/C Description Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numb

343D/Codeforces Round #200 (Div. 1) D. Water Tree dfs序+数据结构

D. Water Tree Mad scientist Mike has constructed a rooted tree, which consists of n vertices. Each vertex is a reservoir which can be either empty or filled with water. The vertices of the tree are numbered from 1 to n with the root at vertex 1. For

Codeforces Round #168 (Div. 1) B. Zero Tree 树形dp

题目链接: http://codeforces.com/problemset/problem/274/B 题意: 给出一棵树,每个点有权值,每次操作可以对一个联通子集中的点全部加1,或者全部减1,且每次操作必须包含点1,问最少通过多少次操作可以让整棵树每个点的权值变为0. 思路: http://blog.csdn.net/qq_24451605/article/details/48622953 定义状态up[u],down[u]代表点u被加操作的次数和点u被减操作的次数 因为必须包含点1,所以我

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

题目链接 题意: 思路: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <algorithm> 6 using namespace std; 7 const int mo = 1000000000 + 7; 8 int dp[110][110][110]; 9 10 int main() 11 { 12