Hdu 4869 Turn the pokers (Mathematics), hdupokers

Source: Internet
Author: User

Hdu 4869 Turn the pokers (Mathematics), hdupokers

Link: hdu 4869 Turn the pokers

Given n and m, it indicates that there are n chances of flop turning. m cards, all cards at the beginning are facing up on the back. You can select xi cards and flip cards at the same time for each flop. How many features are there at the end.

Solution: you only need to determine the number of cards with the last positive orientation. Therefore, you can maintain the upper and lower limits when reading 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;}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.