POJ 1942(组合数学)

来源:互联网 发布:苹果电脑双系统卸载mac 编辑:程序博客网 时间:2024/05/18 02:38

题目链接:http://poj.org/status

题意:简单的来讲,就是求C(n,m).

但是这题有毒..TLE2发也是醉了..

必须循环较小的一个,否则就会TLE。。

#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespace std;const int INF=0x3f3f3f3f;const int Hashmaxn=100000;const int maxn=10010;typedef unsigned long long ULL;ULL n,m;ULL C(ULL n,ULL m){ULL res=1;for(ULL i=m+1,j=1;i<=n;i++,j++){res=res*i/j;}return res;}int main(){#ifndef ONLINE_JUDGEfreopen("test.in","r",stdin);freopen("test.out","w",stdout);#endifwhile(cin>>n>>m){if(!n&&!m) break;if(n>m)cout<<C(n+m,n)<<endl;elsecout<<C(n+m,m)<<endl;}return 0;}


0 0