http://acm.nyist.net/JudgeOnline/problem.php?pid=451
2011-11-25 12:16
295 查看
这是一道关于错误排列的组合题。。。
错误排列方法:
a[1]=0,a[2]=1;
for(L i=3;i<=20;++i)
a[i]=(i-1)*(a[i-1]+a[i-2]);本题代码:
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long L;
L a[25];
L n,m;
L f(L a,L b)
{ L s=1;
for(L i=a;i<=b;++i)
s*=i;
return s;
}
int main()
{ a[1]=0,a[2]=1;
for(L i=3;i<=20;++i)
a[i]=(i-1)*(a[i-1]+a[i-2]);
while(~scanf("%lld%lld",&n,&m))
{ L s1=f(n-m+1,n);
L s2=f(1,m);
printf("%lld\n",a[m]*(s1/s2));
}
return 0;
}
错误排列方法:
a[1]=0,a[2]=1;
for(L i=3;i<=20;++i)
a[i]=(i-1)*(a[i-1]+a[i-2]);本题代码:
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long L;
L a[25];
L n,m;
L f(L a,L b)
{ L s=1;
for(L i=a;i<=b;++i)
s*=i;
return s;
}
int main()
{ a[1]=0,a[2]=1;
for(L i=3;i<=20;++i)
a[i]=(i-1)*(a[i-1]+a[i-2]);
while(~scanf("%lld%lld",&n,&m))
{ L s1=f(n-m+1,n);
L s2=f(1,m);
printf("%lld\n",a[m]*(s1/s2));
}
return 0;
}
相关文章推荐
- 数的长度http://acm.nyist.net/JudgeOnline/problem.php?pid=69
- 超级台阶http://acm.nyist.net/JudgeOnline/problem.php?pid=76
- http://acm.nyist.net/JudgeOnline/problem.php?pid=290
- http://acm.nyist.net/JudgeOnline/problem.php?pid=13
- http://acm.nyist.net/JudgeOnline/problem.php?pid=120&&强连通分量
- 独木舟上的旅行http://acm.nyist.net/JudgeOnline/problem.php?pid=71
- nyoj 21 到水问题 http://acm.nyist.net/JudgeOnline/problem.php?pid=21
- 表达式求值 http://acm.nyist.net/JudgeOnline/problem.php?pid=305
- http://acm.nyist.net/JudgeOnline/problem.php?pid=325
- 取石子(一)http://acm.nyist.net/JudgeOnline/problem.php?pid=23
- 最小点覆盖集&&http://acm.nyist.net/JudgeOnline/problem.php?pid=237
- 幸运三角形&&http://acm.nyist.net/JudgeOnline/problem.php?pid=491
- 矩形嵌套 DP 南阳理工 http://acm.nyist.net/JudgeOnline/problem.php?pid=16
- http://acm.nyist.net/JudgeOnline/problem.php?pid=431
- 荷兰国旗问题 http://acm.nyist.net/JudgeOnline/problem.php?pid=268
- 分数加减法 http://acm.nyist.net/JudgeOnline/problem.php?pid=111
- http://acm.nyist.net/JudgeOnline/problem.php?pid=90
- http://acm.nyist.net/JudgeOnline/problem.php?pid=32&&DFS
- http://acm.nyist.net/JudgeOnline/problem.php?pid=115&&Dijkstra城市平叛
- http://acm.nyist.net/JudgeOnline/problem.php?pid=148&&矩阵求fibonacci数列