09年8月9日 ECUST ACM 练习赛总结
#include<iostream>
using namespace std;
__int64 fn[21][21] = {0};
__int64 njc[21] = {0,1};
__int64 gcd(__int64 a,__int64 b)
{
if(a % b == 0)
return b;
return gcd(b,a % b);
}
int main()
{
for(__int64 i = 2 ; i < 21 ; i ++)
njc[i] = njc[i - 1] * i;
for(int i = 0 ; i < 21 ; i ++)
fn[i][0] = 1;
for(int i = 2 ; i < 21 ; i ++)
{
//放在最后一位
for(int j = 1 ; j < i - 1 ; j ++)
fn[i][j] += fn[i - 1][j];
//不放在最后一位
for(int j = 1 ; j < i ; j ++)
fn[i][j] += fn[i - 1][j - 1] * (i - 1);
}
int t,w,h,s;
cin>>t;
while(t --)
{
cin>>w>>h>>s;
int tol = w * h;
__int64 tmpInt = 0;
for(int i = 0 ; i < s ; i ++)
tmpInt += fn[tol][i];
if(tmpInt == njc[tol])
cout<<1<<endl;
else if(tmpInt == 0)
cout<<0<<endl;
else
{
__int64 base = gcd(tmpInt,njc[tol]) ;
cout<<tmpInt / base<<"/"<<njc[tol] / base<<endl;
}
}
return 0;
}Problem C
Last updated
Was this helpful?