hdu 4869 Turn the pokers(數學),hdupokers

來源:互聯網
上載者:User

hdu 4869 Turn the pokers(數學),hdupokers

題目連結:hdu 4869 Turn the pokers

題目大意:給定n和m,表示有n次翻牌的機會,m張牌,一開始所有的牌均背面朝上,每次翻牌可以選擇xi張牌同時翻轉。問說最後有多少種能。

解題思路:只要確定最後正面朝上的牌的個數即可。所以在讀入xi的時候維護上下限即可。

#include <cstdio>#include <cstring>#include <algorithm>using namespace std;typedef long long ll;//typedef __int64 ll;const ll mod = 1e9+9;const int maxn = 1e5+10;int n, m, l, r;ll c[maxn];ll pow_mod (ll x, int k) {    ll ans = 1;    while (k) {        if (k&1)            ans = ans * x % mod;        x = x * x % mod;        k /= 2;    }    return ans;}void init () {    int x, p, q;    l = r = 0;    for (int i = 0; i < n; i++) {        scanf("%d", &x);        if (l >= x)            p = l - x;        else if (r >= x)            p = ( (l&1) == (x&1) ? 0 : 1);        else            p = x - r;        if (r + x <= m)            q = r + x;        else if (l + x <= m)            q = ( ((l+x)&1) == (m&1) ? m : m-1);        else            q = 2 * m - l - x;        l = p;        r = q;    }}ll solve () {    c[0] = 1;    ll ans = 0;    for (int i = 0; i <= r; i++) {        if (i) {            if (m - i < i)                c[i] = c[m-i];            else                //c[i] = c[i-1] * (m-i+1) % mod * pow_mod(i, mod-2)  % mod;                c[i] = c[i-1] * ( (ll)(m-i+1) * pow_mod(i, mod-2)  % mod) % mod;        }        if (i >= l && (i&1) == (l&1))            ans = (ans + c[i]) % mod;    }    return ans;}int main () {    while (scanf("%d%d", &n, &m) == 2) {        init();        printf("%lld\n", solve());    }    return 0;}



聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.