码迷,mamicode.com
首页 > Web开发 > 详细

[JSOI2015] 子集选取

时间:2020-02-24 20:57:09      阅读:84      评论:0      收藏:0      [点我收藏+]

标签:inline   pre   ||   题解   元素   main   一个   online   tps   

题面

题解

由于每个元素是独立的, 所以我们只用对于每个元素都算一次就行了

对于单一的一个元素, 可以看成从最左下角引一条向右或向上的折线, 折线左上方这个元素都被选, 折线右下方都不选

因为总共向右或向上只能走 \(k\) 步, 每次向右或向上均可, 所以是 \(2 ^ k\)

再来个 \(n\) 次幂代表元素之间互相独立即可

注意欧拉定理

Code

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int mod = 1e9 + 7; 
using namespace std;

int n, k; 

template < typename T >
inline T read()
{
    T x = 0, w = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * w; 
}

int fpow(int x, int y)
{
    int res = 1;
    for( ; y; y >>= 1, x = 1ll * x * x % mod)
    if(y & 1) res = 1ll * res * x % mod;
    return res; 
}

int main()
{
    n = read <int> (), k = read <int> ();
    printf("%d\n", fpow(2, 1ll * n * k % (mod - 1))); 
    return 0; 
}

[JSOI2015] 子集选取

标签:inline   pre   ||   题解   元素   main   一个   online   tps   

原文地址:https://www.cnblogs.com/ztlztl/p/12358471.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!