[BZOJ4475] [Jsoi2015] selected subset

Title Description

img

data range

\ (1 \ leq N, K \ leq 10 ^ 9 \)

\(solution\)

Each element of the set S independently of each other, which might occur is considered in turn in the case of a triangle element

Is transformed into a \ (0/1 \) triangle \ (\ A_ {{I, J} \} \) , with \ (0 \) represents the election, \ (1 \) represents not selected, then if \ (A_ {i, j} \ ) of \ (1 \) , then \ (A_ {i, j} \ ) left and top edges are \ (1 \)

Consider \ (n-\) is relatively small, it is possible DP

\ (F_i \) represents a \ (i * i \) a number of triangular scheme

For \ (F_i \) , the first \ (I \) line period must be \ (1 \) and period \ (0 \) put together, enumeration \ (1 \) length \ (J \) , before \ ( J \) elements must be selected from the column \ (1 \) , removing the first additional column \ (I \) line length to form a \ ((ij-1) \ ) triangles, filled law \ (f_ {ij- 1} \) species

Finally, add the first \ (i \) line Select \ (1 \) cases, only \ (1 \) species

\(f_i=1+\sum_{j=0}^{i-1}f_{i-j-1}=1+\sum_{j=0}^{i-1}f_j\)

\(f_0=1\)

Might make \ (S_i = \ sum_ {j = 0} ^ if_j \)

Original formula \ (f_i = 1 + S_ { i-1} \) i.e. \ (S_ {i-1} = f_i-1 \)

There

\(S_i-S_{i-1}=(f_{i+1}-1)-(f_i-1)\)

\(f_i=f_{i+1}-f_{i}\)

\(f_{i+1}=2*f_i\)\(f_0=1\)

To give \ (f_n = 2 ^ n \ )

\ (F_n year = {} ^ k = 2 ^ {nk} \)

#include<iostream>
#include<cstring>
#include<cstdio>
#define int long long
using namespace std;

const int MOD=1000000007;

int n,k;

inline int qpow(int x,int k){
    int s=1;
    while(k){
        if(k&1) s=s*x%MOD;
        k>>=1;
        x=x*x%MOD;
    }
    return s;
}

signed main()
{
    scanf("%lld%lld",&n,&k);
    printf("%lld\n",qpow(2,n*k));
    return 0;
}

Guess you like

Origin www.cnblogs.com/yjkhhh/p/11712355.html