<模板>Hdu4869 Turn the pokers 组合数求余 费马小定理

Turn the pokers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1115    Accepted Submission(s): 418


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 many 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 4 3 2 3 3 3 3 2 3
 

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


题意:有M张牌,N次操作,每次翻转xi张牌,问最后有多少种情况。

题解:不论前面怎么翻转,我们只需要知道最后牌的状态是哪几种,然后求组合数就可以了,比如有6张牌,两张向上,或四张向上。这里有个很神奇的地方,比赛的时候没有想到,最后的结果只需要知道最少是多少张朝上,最多有多少张朝上,他们的状态都是同奇或者同偶。比如最少1张向上,那么他们其他状态一定是1+2i张向上的,所有我们只需要左右区间即可。不信你自己模拟翻一翻牌就知道了。然后就是我们得仔细考虑怎么求最小最大了。这个多YY多推敲,万一不行就实践试试总会搞出来的。so我们知道最后牌的几种状态k=[L,R](位置可以不同),所以接下来就需要求这些状态的组合数了C(M,k)。这里数据好像很大的样子。我们可以考虑用这个不记得是费马小定理还是什么东西。(a/b)%M=a*(b^(M-2))%M。我们可以把组合数C(M,i)==C(M,i-1)*(M-i+1)/i 这个关系.套用左边那个公式。递推求得所有C(M,X)的值,然后找到区间[L,R]的组合数相加,即是最后的解。

增加一个链接:http://blog.youkuaiyun.com/modiz/article/details/38257837

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <vector>
using namespace std;
#define LL __int64
//#define DEBUG
const LL M=1000000009;
LL c[100110];
LL ksm(LL a,LL b)
{
	LL ans=1;
	while (b)
	{
		if (b&1)
			ans=ans* a % M;
		b>>=1;
		a=a*a%M;
	}
	return ans;
}
int main()
{
	LL n,m;
//	freopen("1009.in","r",stdin);
	while (~scanf("%I64d%I64d",&n,&m))
	{
		LL l=0,r=0;
		for (int i=1;i<=n;i++)
		{
			LL ll,rr,x;
			scanf("%I64d",&x);
			if (l>=x) ll=l-x;
			else if (r>=x) ll=(l+x)&1;
			else ll=x-r;
			if (r+x<=m) rr=r+x;
			else if (l+x<=m) rr=m-((m+l+x)&1);
			else rr=2*m-l-x;
			l=ll;
			r=rr;
		}
		c[0]=1;
	//	cout<<l<<" "<<r<<endl;
		for (int i=1;i<=m;i++)
			if (m-i<i) c[i]=c[m-i];
			else c[i]=((c[i-1]*(m-i+1))%M * ksm(i,M-2))%M;
		LL ans=0;
		for (int i=l;i<=r;i+=2)
			ans=(ans+c[i]) % M;
		cout<<ans<<endl;
	}
	return 0;
}


在CUDA编程中,kernel<<<>>>是用来启动并行计算的语法。在<<<>>>中,必须指定一个表达式作为参数,该表达式指定了并行计算的线程块(block)和线程(thread)的数量。这个表达式的格式可以是一个常数,也可以是一个变量或者一个计算表达式。 例如,如果想要启动一个有16个线程块和256个线程的并行计算,可以使用以下形式的表达式: kernel<<<16, 256>>>(); 其中,16表示线程块的数量,256表示每个线程块中的线程数量。 另外,如果希望在编译时指定默认的线程块和线程数量,可以使用宏定义或者模板的方式来实现。通过设置默认值,并在调用kernel时不指定表达式,就可以使用默认的线程块和线程数量。同时,也可以添加依赖关系来根据不同的条件设置不同的默认值。 总结起来,当使用kernel<<<>>>时,必须提供一个表达式来指定线程块和线程的数量。这个表达式可以是一个常数、变量或者计算表达式。另外,也可以通过设置默认值和添加依赖关系来实现更灵活的使用方式。<span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* [玩转CUDA——提示应输入表达式](https://blog.youkuaiyun.com/gaohang_hdu/article/details/81119627)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Kconfig语法](https://download.youkuaiyun.com/download/pengfei24/4328218)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值