zoukankan      html  css  js  c++  java
  • CodeChef

    题意:有一种关系叫继承,那么继承父类的同时也会继承他的一个函数f,能继承任意多个父类或不继承,但不能继承自己的子类。现在规定一个列表,这个列表必须以1~N的顺序排列,并且父类不会排在子类后面,1含有一个函数f,有多少种可能使得这样一个列表每个数都继承f,取模1e9+7

    思路:终于做出了一道DP(?)题。题目的意思其实就是有几种连法让每个数直接或者间接和1相连。那么我们假设dp[i]表示连到位置i时一共有多少种连法,那么dp[i] = dp[i - 1] * (2i - 1 - 1),因为i前面已经连好了,我只要管i怎么连,那么i - 1条线至少取1条。

    代码:

    #include<set>
    #include<map>
    #include<stack>
    #include<cmath>
    #include<queue>
    #include<vector>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    typedef long long ll;
    using namespace std;
    const int maxn = 1e5 + 10;
    const int seed = 131;
    const ll MOD = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    ll dp[maxn];
    int main(){
        int t, n;
        dp[1] = 1;
        ll bit = 2;
        for(int i = 2; i <= 100005; i++){
            dp[i] = dp[i - 1] * (bit - 1LL) % MOD;
            bit = bit * 2 % MOD;
        }
        scanf("%d", &t);
        while(t--){
           scanf("%d", &n);
           printf("%lld
    ", dp[n]);
        }
        return 0;
    }
  • 相关阅读:
    poj2352树状数组
    hdu1166树状数组
    poj2785双向搜索
    poj2566尺取变形
    poj2100还是尺取
    poj3061尺取法
    poj3320尺取法
    hdu3829最大独立集
    poj2594最小顶点覆盖+传递闭包
    经典换根dp——hdu2196
  • 原文地址:https://www.cnblogs.com/KirinSB/p/10230979.html
Copyright © 2011-2022 走看看