zoukankan      html  css  js  c++  java
  • k-Tree DP计数

    k-Tree

    对dp数情况的问题还是不太懂

    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    #include <cassert>
    //#include <unordered_set>
    //#include <unordered_map>
    #define ll              long long
    #define pii             pair<int, int>
    #define rep(i,a,b)      for(ll  i=a;i<=b;i++)
    #define dec(i,a,b)      for(ll  i=a;i>=b;i--)
    #define forn(i, n)      for(ll i = 0; i < int(n); i++)
    using namespace std;
    int dir[4][2] = { { 1,0 },{ 0,1 } ,{ 0,-1 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = acos(-1.0);
    const double eps = 1e-6;
    const int mod = 1e9 + 7;
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    inline ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m % n);
    }
    void exgcd(ll A, ll B, ll& x, ll& y)
    {
        if (B) exgcd(B, A % B, y, x), y -= A / B * x; else x = 1, y = 0;
    }
    inline int qpow(int x, ll n) {
        int r = 1;
        while (n > 0) {
            if (n & 1) r = 1ll * r * x % mod;
            n >>= 1; x = 1ll * x * x % mod;
        }
        return r;
    }
    /**********************************************************/
    const int N = 100 + 5;
    ll dp[N][2];
    
    int main() {
        cin.tie(0);cout.tie(0);
    
        ll n, k, d;
        cin >> n >> k >> d;
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        rep(i, 1, n)
        {
            rep(j, 1, k)
            {
                if (i - j < 0)
                    break;
                if (j < d)
                {
                    dp[i][0] = (dp[i][0] + dp[i - j][0]) % mod;
                    dp[i][1] = (dp[i][1] + dp[i - j][1]) % mod;
                }
                else
                {
                    dp[i][1] = (dp[i][1] + dp[i - j][0]) % mod;
                    dp[i][1] = (dp[i][1] + dp[i - j][1]) % mod;
                }
            }
        }
        cout << dp[n][1] << endl;
    }
  • 相关阅读:
    appfabric cache配置,实验记录
    appfabric cache存储ef 查询结果的bug
    CruiseControl.NET svn获取 自动编译 ftp上传
    @Ajax.RenderAction 把局部页改为ajax加载
    分布式架构下的mvc 异步controller ajax comet 长连接
    win7重装iis,搞死
    验证码识别的基本思路及方法
    C# 获取程序当前文件夹
    在c#中 限制文本框只能输入数字
    string字符串 获取指定位置范围的子字符串
  • 原文地址:https://www.cnblogs.com/dealer/p/13383091.html
Copyright © 2011-2022 走看看