HDU 4869 Turn the pokers, hdupokers

Source: Internet
Author: User

HDU 4869 Turn the pokers, hdupokers
Turn the pokers

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Problem Description

During summer vacation, Alice stay at home for a long time, with nothing to do. she went out and bought m pokers, tending to play poker. but she hated the traditional gameplay. she wants to change. she puts these pokers face down, she decided to flip poker n times, and each time she can flip Xi pokers. she wanted to know how to handle the results does she get. can you help her solve this problem?

 

 

Input

The input consists of multiple test cases.
Each test case begins with a line containing two non-negative integers n and m (0 <n, m <= 100000 ).
The next line contains n integers Xi (0 <= Xi <= m ).

 

 

Output

Output the required answer modulo 1000000009 for each test case, one per line.

 

 

Sample Input

3 43 2 33 33 2 3

 

 

Sample Output

83

Hint

For the second example: 0 express face down, 1 express face upInitial state 000The first result: 000-> 111-> 001-> 110The second result: 000-> 111-> 100-> 011The third result: 000-> 111-> 010-> 101So, there are three kinds of results (110,011,101)



Period maintenance is very difficult !!!!! I thought it was easy, and I had no limit !!

There is also a rapid power Modulo for the combination of numbers. I didn't remember this before !!!

Solve the problem and finally make it A after the game!


The AC code is as follows:


# Include <cstdio> # include <iostream> # include <cstring> # define mod 1000000009 # define ll long # define M 100005 using namespace std; ll n, m; ll a [M], c [M]; ll pow_mod (ll a, ll B) {ll s = 1; while (B) {if (B & 1) s = s * a % mod; a = a * a % mod; B = B> 1;} return s;} int main () {ll I, j; ll ans, minn, maxx; while (~ Scanf ("% lld", & n, & m) {ans = 0; ll l = 0, r = 0; for (I = 0; I <n; I ++) {scanf ("% lld", & a [I]); if (a [I] = m | a [I] = 0) continue; if (r + a [I] <= m) // change the right interval maxx = r + a [I]; else if (l + a [I] <= m) maxx = (m + l + a [I]) & 1 )? M-1: m; else maxx = m + m-l-a [I]; if (l-a [I]> = 0) // minn = l-a [I]; else if (r-a [I]> = 0) minn = (l + a [I]) & 1 )? 1:0; else minn = a [I]-r; l = minn; r = maxx;} // cout <l <"~~~~~~~~ "<R <endl; c [0] = 1; for (ll k = 1; k <= m; k ++) // modulo {if (m-k <k) c [k] = c [m-k]; else c [k] = c [k-1] * (m-k + 1) % mod * pow_mod (k, mod-2) % mod;} for (I = l; I <= r; I + = 2) // The interval must be the same as the parity of ans = (ans + c [I]) % mod; printf ("% I64d \ n ", ans);} 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.