【组合数】hrbustoj 1744 Pascal's Triangle
来源:互联网 发布:mac os 10.11 iso镜像 编辑:程序博客网 时间:2024/05/22 03:48
Pascal's TriangleTime Limit: 1000 MSMemory Limit: 65535 KTotal Submit: 115(23 users)Total Accepted: 27(16 users)Rating: Special Judge: NoDescription
题意:看第二幅图片,求和:第m条对角线的前k个数的和;
The figure below shows Pascal's Triangle:
Baby H divides Pascal's Triangle into some Diagonals, like the following figure:
Baby H wants to know the sum of K number in front on the Mth diagonal. Try to calculate it.
There are multiple test cases. The first line is a positive integer T (1<=T<=100) indicating the number of test cases.
For each test case:
Line 1. Two positive integers M and K (1<= M , K <= 100 000).
For each test case, output the sum of K number in front on the Mth diagonal in one line. The answer should modulo to 20 000 003.
Sample Input22 33 4Sample Output
620Source哈理工2013春季校赛 - 现场赛SubmitStatisticDiscussSharedcodes
思路:组合数取模(数据小),预处理阶乘与阶乘的逆元;
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long ll;#define mod 20000003const int maxn=1000005;ll fac[maxn+10],inv[maxn+10];ll mod_pow(ll x,ll n){ ll res=1; while(n>0) { if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res%mod;}void init(){ fac[0]=1;fac[1]=1; for(ll i=2;i<=maxn;i++) { fac[i]=fac[i-1]*i*1LL; fac[i]%=mod; } inv[maxn]=mod_pow(fac[maxn],mod-2); for(int i=maxn-1;i>=0;i--) inv[i]=(inv[i+1]*(i+1))%mod;}ll C(ll n,ll m){ return fac[n]*inv[m]%mod*inv[n-m]%mod;}int main(){ int T; init(); scanf("%d",&T); while(T--) { ll m,k; ll res=0; scanf("%lld%lld",&m,&k); for(ll i=m-1;i<m-1+k;i++) {// printf("%d ",C(i,m-1)); res=res+C(i,m-1); res%=mod; } printf("%lld\n",res); } return 0;}
阅读全文
0 0
- 【组合数】hrbustoj 1744 Pascal's Triangle
- Pascal's Triangle、Pascal's Triangle II
- Pascal's Triangle , Pascal's Triangle II
- Pascal's Triangle Pascal's Triangle||
- Pascal's Triangle & Pascal's Triangle II
- Pascal's Triangle && Pascal's Triangle II
- 【Leetcode】Pascal's Triangle (Pascal)
- LeetCode Pascal's Triangle
- [Leetcode] Pascal's Triangle
- LeetCode: Pascal's Triangle
- Pascal's Triangle
- Pascal's Triangle II
- [LeetCode] Pascal's Triangle
- 【leetcode】Pascal's Triangle
- [118]Pascal's Triangle
- Pascal's Triangle
- Pascal's Triangle II
- LeetCode - Pascal's Triangle
- Java设计模式在Android中应用
- JDBC学习心得
- PTA甲 1101. Quick Sort (25)
- 如何用人工智能分辨出一个苹果?
- Linux下通过ssh-keygen和ssh-copy-id命令实现ssh无密码登录访问
- 【组合数】hrbustoj 1744 Pascal's Triangle
- 端口复用和重映射
- tomcat 性能优化
- 7_21|C语言|操作符注意事项|sizeof使用讲解|结构体简单介绍
- h5
- mybatis-pagehelper插件配置
- http://blog.csdn.net/w00w12l/article/details/8143591?locationNum=14&fps=1 转载请注明出处 Android异步处理系列文章索引
- 事物的4种特性(ACID)解析
- 欢迎使用CSDN-markdown编辑器