车(唯一分解定理+高精度乘以单精度)
来源:互联网 发布:crossover linux 破解 编辑:程序博客网 时间:2024/06/05 15:06
车
题目描述:
众所周知,车是中国象棋中最厉害的一子之一,它能吃到同一行或同一列
中的其他棋车。车跟车显然不能在一起打起来,于是rly一天又借来了许多许多的车在棋盘上摆了起来……他想知道,在N×M的矩形方格中摆最多个数的车使其互不吃到的情况下方案数有几种。但是,由于上次摆炮摆得实在太累,他为了偷懒,打算增加一个条件:对于任何一个车A,如果有其他一个车B在它的上方(车B行号小于车A),那么车A必须在车B的右边(车A列号大于车B)。
棋子都是相同的。
输入说明:
一行,两个正整数N和M。
输出说明:
一行,输出方案数的末尾50位(不足则直接输出)。
样例输入:
2 2
样例输出:
1
数据范围:
对于20%的数据, N<=10, M<=10。
对于40%的数据, N<=40, M<=40。
对于70%的数据, N<=10000, M<=10000。
对于100%的数据, N<=1000000, M<=1000000。
思路:
观察后可以发现答案为C(n,m)(n>m)
因为C(n,m)=!n/!m*!(n-m)用唯一分解定理分解的变形快速分解!n,!m,!(n-m)
最后高精度乘以单精度求出乘积即可。
#include<iostream>#include<cstdio>using namespace std;const int maxn=1000010;int n,m,tot,a[maxn],prime[maxn],ans[maxn];int sa[maxn],sb[maxn];bool flag[maxn];void prepare(){ for(int i=2;i<=n;i++) if(!flag[i]) { prime[++tot]=i; for(int j=i+i;j<=n;j+=i) flag[j]=1; } for(int i=1;i<=tot;i++) { int t=n; while(t) { a[i]+=t/prime[i]; t/=prime[i]; } } for(int i=1;i<=tot;i++) { int t=m; while(t) { a[i]-=t/prime[i]; t/=prime[i]; } } for(int i=1;i<=tot;i++) { int t=n-m; while(t) { a[i]-=t/prime[i]; t/=prime[i]; } }}void mul(int *a,int b){ for(int i=1;i<=min(a[0],52);i++) a[i]=a[i]*b; for(int i=1;i<=min(a[0],52);i++) { a[i+1]=a[i+1]+a[i]/10; a[i]%=10; } while(a[a[0]+1]&&a[0]<=52) { a[0]++; a[a[0]+1]=a[a[0]+1]+a[a[0]]/10; a[a[0]]%=10; }}int main(){ freopen("rook.in","r",stdin); freopen("rook.out","w",stdout); scanf("%d%d",&n,&m); if(n<m) swap(n,m); prepare(); ans[0]=1,ans[1]=1; for(int i=1;i<=tot;i++) for(int j=1;j<=a[i];j++) mul(ans,prime[i]); if(ans[0]<=50) for(int i=ans[0];i>=1;i--) cout<<ans[i]; else for(int i=50;i>=1;i--) cout<<ans[i]; fclose(stdin);fclose(stdout); return 0;}
1 0
- 车(唯一分解定理+高精度乘以单精度)
- 高精度乘以单精度 hdu1042 N!
- 高精度乘以单精度 Round and Round We Go poj1047
- uva10375(唯一分解定理)
- 唯一分解定理(数论)
- UVa10375(唯一分解定理)
- uva10375(唯一分解定理)
- uva10791(唯一分解定理)
- 超大整数乘法模板(高精度乘以低精度)
- 质因数分解(唯一分解定理)
- 质因数分解(唯一分解定理)
- 算数基本定理(唯一分解定理)
- 算术基本定理(唯一分解定理)
- 【定理】算术基本定理(唯一分解定理)
- Pairs Forming LCM(唯一分解定理)
- 算数基本原理(唯一分解定理)
- 唯一分解定理
- 唯一分解定理
- 女巫终于变黑猫了
- 欢迎使用CSDN-markdown编辑器
- onActivityResult回调的用法
- 写一个复数类Complex,(复数形如3.2+5.6i,2.9-1.3i,其中i*i=-1)。要求支持+-*/,++、--,到bool类型和string类型的转换,支持>>、<<运算符。
- Spring Batch Partitioning example
- 车(唯一分解定理+高精度乘以单精度)
- 7. Scaling and Parallel Processing
- Bash中的可执行命令
- namespace 命名空间
- 信用风险评估评分卡 之 极端值
- Jsp简介
- file change只触发一次 解决方案
- 理解面向对象
- Can’t connect to local MySQL server through socket 解决办法