UVALive 6469 Deranged Exams 组合数学+容斥原理
来源:互联网 发布:淘宝上买iphone店铺 编辑:程序博客网 时间:2024/04/30 05:47
这个题目的大概意思是:给n个座位。每个座位都有对应的人。问:至少前k个座位都坐错的种数。
直接求至少前k个座位都坐错的话有点难求。。
直接求总数-反例
把问题转换为:求至多有前k个座位坐对的总数。
假设有n=7 k=3
我们求前1个座位坐对的总数为:
C(3,1)*A(6,6)
但是考虑到这样的话会把1 3 1 2 2 3给算重
要减去1 2 1 3 2 3的总数。就是要减去C(3,2)*A(5,5)
但是减去的话又会多减去2 3的情况所以又要加上C(3,3)*A(4,4)
然后我们看一下
C(3,1)*A(6,6)-C(3,2)*A(5,5)+C(3,3)*A(4,4)
基本上就这样了。详情看代码
//First Edit Time:2014-07-15 19:15//Last Edit Time:2014-07-15 19:35//Filename:E.cpp#include <map>#include <set>#include <cmath>#include <queue>#include <stack>#include <vector>#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>#define LL long longusing namespace std;LL c[20][20];LL a[20];int main(){ a[0]=1; a[1]=1; c[1][0]=c[1][1]=1; for(int i=2;i<=17;i++) { a[i]=a[i-1]*i; c[i][0]=c[i][i]=1; for(int j=1;j<i;j++) c[i][j]=c[i-1][j]+c[i-1][j-1]; } int t; scanf("%d",&t); while(t--) { int cas,n,k; scanf("%d%d%d",&cas,&n,&k); if(k==0) { printf("%d %lld\n",cas,a[n]); continue; } LL ans=0; for(int i=1;i<=k;i++) { if(i&1) ans+=(c[k][i])*a[n-i]; else ans-=(c[k][i])*a[n-i]; } printf("%d %lld\n",cas,a[n]-ans); } return 0;}
0 0
- UVALive 6469 Deranged Exams 组合数学+容斥原理
- UVALive 6469 Deranged Exams
- UVALive 6469 Deranged Exams (排列组合:绝逼是纯纯的高中知识啊)
- UVALive 7040 Color (容斥原理 + 组合数学递推公式 + 求逆元 + 基础数论)
- UVALive 7040 Color 容斥原理 + 组合数学递推公式 +lucas
- UVALive 7040 Color (容斥原理 + 组合数学递推公式 + 求逆元 + 基础数论)
- (组合数学3.3.2.1)URAL 1091. Tmutarakan Exams(容斥定理)
- 组合数学-容斥原理专辑
- 组合数学 容斥原理 专题
- 容斥原理+质因数分解+组合数学
- 组合数学:容斥原理及其应用
- 组合数学之容斥原理
- 【组合数学】八(容斥原理)
- 容斥原理(组合数学)总结
- Ural 1091 Tmutarakan Exams [容斥原理]
- URAL1091 Tmutarakan Exams (容斥原理)
- Ural 1091 Tmutarakan Exams【容斥原理】
- URAL 1091 Tmutarakan Exams(容斥原理)
- poj 1523 tarjan求割点
- 由《小道消息 • 思维偏误》说开来。
- MATLAB 与 PostgreSQL 数据库的连接
- poj-1961-Period
- 一个microsoft的.exe程序文件的启动过程 .
- UVALive 6469 Deranged Exams 组合数学+容斥原理
- 思考,领悟,前进
- 【阅读】《Head First Servlets & JSP》第九章——强大的定制标记
- 小甲鱼老师目前所有视频教程下载地址
- android各种声音类型级数设定及默认值
- __USE_GNU的问题
- tomcat的搭建
- protobuf嵌套类操作实例
- shell 中的printf用法