UVa 11481 Arrange the Number(容斥原理)
来源:互联网 发布:网络安全设备巡检报告 编辑:程序博客网 时间:2024/05/20 11:36
从M中选定K个不变的数是C[M][K]种方案,对于每种方案容斥,在剩下的N-K个数中不能有不变的,那么就要减掉有一个不变的,加上有两个不变的,减去3个不变的。。。以此类推。
代码:
//// main.cpp// 11481 Arrange the Number//// Created by Baoli1100 on 15/2/28.// Copyright (c) 2015年 Baoli1100. All rights reserved.//#include <iostream>#include <cstdio>#include <cstring>using namespace std;#include <algorithm>#define LL long longconst LL mod=1000000007;LL C[1005][1005];LL k[1005];int N,M,K;int main(){ C[0][0]=1; for(int i=1;i<=1000;i++){ C[i][0]=1;C[i][i]=1; for(int j=1;j<i;j++){ C[i][j]=C[i-1][j-1]+C[i-1][j]; C[i][j]%=mod; } } k[0]=1; for(int i=1;i<=1000;i++){ k[i]=k[i-1]*i; k[i]%=mod; } int T; cin>>T; for(int kase=1;kase<=T;kase++){ scanf("%d%d%d",&N,&M,&K); LL res=0; for(int i=0;i<=M-K;i++){ if(i&1){ res-=(C[M-K][i]*k[N-K-i])%mod; while(res<0) res+=mod; } else { res+=C[M-K][i]*k[N-K-i]; res%=mod; } } res*=C[M][K]; res%=mod; printf("Case %d: %lld\n",kase,res); } return 0;}
0 0
- UVa 11481 Arrange the Number(容斥原理)
- UVa 11481 Arrange the Numbers (组合数学+容斥原理)
- UVA 11481 Arrange the Numbers (容斥)
- LightOJ 1095 Arrange the Numbers (容斥原理)
- Light OJ 1095 Arrange the Numbers (容斥)
- uva 11481 Arrange the Numbers
- UVa:11481 Arrange the Numbers
- UVA - 11481 Arrange the Numbers
- UVA 11481 - Arrange the Numbers(组合数学)
- uva 10325 The Lottery(组合数学-容斥原理)
- UVA 10325 The Lottery(容斥原理)
- UVA 10325 The Lottery(容斥原理)
- UVA 10325 The Lottery( 容斥原理)
- UVa 10325 The Lottery 容斥原理
- uva 11481 - Arrange the Numbers(计数问题)
- UVALive 4683 Find The Number(容斥原理)
- uva 10325 The Lottery 枚举子集+容斥原理
- UVA 10325 (容斥原理)
- OC的内存管理
- 2014年——任性
- linux grep命令
- C语言版五子棋
- Edit Distance
- UVa 11481 Arrange the Number(容斥原理)
- 五子棋人机对弈
- mysql SQL语句大全
- android 色值透明度计算
- linux repytr命令介绍
- log4j 级别、多文件输出配置
- 【最小割】【bzoj 3894】: 文理分科
- python的对象引用
- BZOJ 3895 取石子 博弈论+记忆化搜索