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且存在至少为d的边的状态可以由 存在至少为d的边加一条小于d的边转移而来,无论是否存在至少d的边的状态加一条大于等于d的边 转移而来。

dp[n][1]=dp[n-1][1]+dp[n-2][1]+……+dp[n-(d-1)][0]+(dp[n-d][1]+dp[n-d][0])+(dp[n-(d+1)][1]+dp[n-(d+1)][0])+……+(dp[n-(d+1)][1]+dp[n-(d+1)][0])+……+(dp[n-k][1]+dp[n-k][0])

这个题状态设计的很巧妙,可以很好的降低时间复杂度。

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#define mod 1000000007
#define ll long long
using namespace std;
ll dp[][];
int n,k,d;
int main()
{
    cin>>n>>k>>d;
    dp[][]=;
    ; i<=n; ++i)
    {
        ; j<d&&i-j>=; ++j)
        {
            dp[i][]+=dp[i-j][];
            dp[i][]%=mod;
        }
        ; j<=k&&i-j>=; ++j)
        {
            if(j<d)
                dp[i][]+=dp[i-j][];
            else
                dp[i][]+=dp[i-j][]+dp[i-j][];
            dp[i][]%=mod;
        }
    }
    cout<<dp[n][]<<endl;
    ;
}

Codeforces Round #247 (Div. 2)的更多相关文章

  1. Codeforces Round #247 (Div. 2) ABC

    Codeforces Round #247 (Div. 2) http://codeforces.com/contest/431  代码均已投放:https://github.com/illuz/Wa ...

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

    模拟即可 #include <iostream> #include <vector> #include <algorithm> using namespace st ...

  3. Codeforces Round #247 (Div. 2) C题

    赛后想了想,然后就过了.. 赛后....... 我真的很弱啊!想那么多干嘛? 明明知道这题的原型就是求求排列数,这不就是 (F[N]-B[N]+100000007)%100000007: F[N]是1 ...

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

    题目链接 自己的dp, 不是很好,这道dp题是 完全自己做出来的,完全没看题解,还是有点进步,虽然这个dp题比较简单. 题意:一个k叉树, 每一个对应权值1-k, 问最后相加权值为n, 且最大值至少为 ...

  5. [Codeforces Round #247 (Div. 2)] A. Black Square

    A. Black Square time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. Codeforces Round #247 (Div. 2) D. Random Task

    D. Random Task time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  7. Codeforces Round #247 (Div. 2) C D

    这题是一个背包问题 这样的 在一个k子树上 每个节点都有自己的k个孩子 然后 从原点走 走到 某个点的 和为 N 且每条的 长度不小于D 就暂停问这样的 路有多少条,  呵呵 想到了 这样做没有把他敲 ...

  8. 「专题训练」k-Tree(CodeForces Round #247 Div.2 C)

    题意与分析(Codeforces-431C) 题意是这样的:给出K-Tree--一个无限增长的树,它的每个结点都恰有\(K\)个孩子,每个节点到它\(K\)个孩子的\(K\)条边的权重各为\(1,2, ...

  9. Codeforces Round #247 (Div. 2) B

    B. Shower Line time limit per test 1 second memory limit per test 256 megabytes input standard input ...

随机推荐

  1. VC++源文件编码

    目录 第1章源代码文件    1 1.1 研究思路    1 1.2 实验结果    3 1.3 #pragma setlocale    4 1.4 /source-charset    5 1.5 ...

  2. 【Unity技巧】Unity中的优化技术

    http://blog.csdn.net/candycat1992/article/details/42127811 写在前面 这一篇是在Digital Tutors的一个系列教程的基础上总结扩展而得 ...

  3. 【转】 Linux 线程同步的三种方法

    线程的最大特点是资源的共享性,但资源共享中的同步问题是多线程编程的难点.linux下提供了多种方式来处理线程同步,最常用的是互斥锁.条件变量和信号量. 一.互斥锁(mutex) 通过锁机制实现线程间的 ...

  4. examine self thrice a day2016

    ----------------------------2016-----------------------  12.31.2016 2016年,感恩一路帮助过我的所有人!       每个人来到世 ...

  5. 【EPplus】Column width discrepancy

    description Hi Jan, I have noticed that when I set a column width there is a discrepancy between the ...

  6. cookie ,session Storage, local storage

    先来定义: cookie:是网站为了标识用户身份存储在本地终端的数据,其数据始终在APP请求中存在,会在服务器和浏览器中来回传递 数据大小不超过4k, 可以设置有效期,过了有效期自动删除 sessio ...

  7. python 练习 18

    #!/usr/bin/python # -*- coding: UTF-8 -*- import time print time.strftime('%Y-%m-%d %H:%M:%S',time.l ...

  8. c++表达式的一些小小的注意事项

    3+12>>1 = 7; 12>>1+3 =0; 3+(12>>1)=9;

  9. 190. Reverse Bits -- 按位反转

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  10. ios基础篇(五)——UITextField的详细使用

    UItextFieldField通常用于外部数据输入,以实现人机交互. 以下是UItextFieldField的属性及常见用法: 1.textField :设置文本框的默认文本. 2.Placehol ...