UVALive
来源:互联网 发布:星光网络摄像机 编辑:程序博客网 时间:2024/04/29 09:41
题意:N道题连线,问至少前k道题目错误的可能有几种
思路:那就是所有连线可能的情况数(即n!) 减去前k道题存在正确答案的情况数
根据容斥原理,奇数个集合为正,偶数个集合为负计算即可
代码如下:
#include<bits/stdc++.h>using namespace std;typedef long long ll;const ll INF = 1e14 + 7;const int N = 1e5 + 10;int n, k;int main(){ int t, cas; scanf("%d", &t); while(t--) { scanf("%d%d%d", &cas, &n, &k); ll ans = 1; for(int i = 1; i <= n; i++) ans *= i; ll cnt = 0;for(int i = 1; i <= k; i++){ll tmp = 1;for(int j = k; j > k - i; j--){tmp *= j;}for(int j = i; j > 1; j--){tmp /= j;}for(int j = n - i; j >= (n - k + 1); j--) tmp *= j;if(i % 2 == 0) cnt -= tmp;else cnt += tmp;}for(int i = n - k; i > 1; i--) cnt *= i;ans -= cnt;printf("%d %lld\n", cas, ans); } return 0;}/*41 4 12 7 33 10 54 17 17*/
0 0
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- 你画我猜题目库
- Java界面中使用SwingWorker
- Android Studio插件合集
- 应用在后台被强杀的解决方案
- Android java.lang.UnsatisfiedLinkError
- UVALive
- ubuntu下virtualbox的安装、卸载
- Codeforces Round #286 (Div. 1) D. Mr. Kitayuta's Colorful Graph 高维并查集,STL连招
- Qt QLCDNumber Class 与 halcon ORC识别
- Objective-C学习错误总结
- 日语——目录
- 使用MyBatis的默认(数据库字段和属性名忽略大小匹配)映射方式,必须有无惨构造函数。
- angularjs 实现动态添加控件
- JAVA基础训练之模拟双色球实现案列