hdu4073 Lights
题意:找出m个不同的n位2进制数,异或值中前v个为1,其余为0的方案数,答案 % 10567201。。
思路:比赛时第一感觉是用容斥原理做的,然后推呀推,搞了2个小时还是错了。。赛后才知道递推才是正解(也许容斥是可以的,是我太弱了,推不出吧)
因为异或的特性,所以这m个数异或为x(前v个为1,其余为0的m位数),相当于这m个数异或x为0,。。
也就是说如果知道m-1个数,第m个数也唯一被确定了。。
假设f[m]为m个数的方案数,那么不考虑重复的情况下,f[m] = C(2^n, m-1)
那么如何去除重复了,如果出现重复(一定最多只有两个数重复),那么这两个书异或值为0,发现什么了没有。。
也就是去掉这两个数,就是f[m-2]了吧。。
除此之外,对于合法的每一组方案,会算m次吧
so,f[m] = (C(2^n, m-1) - f[m-2] * (2^n - (m-2))) / m;
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cctype>
#include <ctime>
#include <utility>
#define M0(x) memset(x, 0, sizeof(x))
#define clr(x,y) memset(x, y, sizeof(x))
#define P 10567201
#define N 1010
using namespace std;
long long c[][], two[];
int n, m, v;
long long f[N+], inv[N+];
using namespace std; void get_inv(){
inv[] = ;
for (int i = ; i < N; ++i)
inv[i] = (P - P / i) * inv[P % i] % P;
} void pre_do(){
get_inv();
two[] = ;
for (int i = ; i < N; ++i){
two[i] = (two[i-] << );
if (two[i] >= P) two[i] -= P;
}
for (int i = ; i < N; ++i){
c[i][] = ;
for (int j = ; j < N; ++j)
c[i][j] = c[i][j-] * (two[i]-j+) % P * inv[j] % P;
}
} void solve(){
if (v == ) f[] = ;
else f[] = ;
f[] = ;
for (int i = ; i <= m; ++i){
long long same = f[i-] * (two[n]-i+) % P;
f[i] = (c[n][i-] - same) * inv[i] % P;
}
f[m] += (f[m] < ? P : );
printf("%I64d\n", f[m]);
} int main(){
// freopen("a.in","r",stdin);
// freopen("a.out","w",stdout);
pre_do();
while (scanf("%d%d%d", &n, &m, &v) != EOF){
if (!(n+m+v)) break;
solve();
}
return ;
}
hdu4073 Lights的更多相关文章
- HDOJ 4770 Lights Against Dudely
状压+暴力搜索 Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights
[我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights 既上一篇分享了中文字幕的摄像机介绍Cameras后,本篇分享一下第2个已完工的 ...
- poj1222 EXTENDED LIGHTS OUT 高斯消元||枚举
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8481 Accepted: 5479 Description In an ...
- ACM: NBUT 1646 Internet of Lights and Switches - 二进制+map+vector
NBUT 1646 Internet of Lights and Switches Time Limit:5000MS Memory Limit:65535KB 64bit IO Fo ...
- HDU 4770 Lights Against DudelyLights
Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Traffic Lights
Traffic Lights time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- [BZOJ1659][Usaco2006 Mar]Lights Out 关灯
[BZOJ1659][Usaco2006 Mar]Lights Out 关灯 试题描述 奶牛们喜欢在黑暗中睡觉.每天晚上,他们的牲口棚有L(3<=L<=50)盏灯,他们想让亮着的灯尽可能的 ...
- HDU 4770 Lights Against Dudely
Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Codeforces Round #240 (Div. 2)->A. Mashmokh and Lights
A. Mashmokh and Lights time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- instanceof 和 typeof
instanceof 运算符用来检测 constructor.prototype 是否存在于参数 object 的原型链 function Person(){ Person.prototype.dan ...
- 简单使用DESeq2/EdgeR做差异分析
简单使用DESeq2/EdgeR做差异分析 Posted: 五月 07, 2017 Under: Transcriptomics By Kai no Comments DESeq2和EdgeR都 ...
- ubuntu12.04下Qt调试器的使用
最近,我一直在用Qt编写C++程序,但在编写过程中遇到了问题,想用Qt Creator中的调试器调试一下,但调试时(在Qt Creator中已配置好相应的调试器)出现“ ptrace:Operatio ...
- 201621123008 《Java 程序设计》 第九周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 2. 书面作业 本次作业题集集合 1. List中指定元素的删除(题集题目) 1.1 实验总结.并回答:列举至 ...
- Android Text Color设置不当造成信息不显示
Android Text Color设置不当造成信息不显示 Android 的TextView 可以设置颜色,默认我们可以设置成 #000000 ,但某一次设置成了#00000000 ,就是多了两个0 ...
- [SoapUI] 在SoapUI中通过Groovy脚本执行window命令杀掉进程
//杀Excel进程 String line def p = "taskkill /F /IM EXCEL.exe".execute() def bri = new Buffere ...
- PHP数组对象互转
//数组转对象 function array2object($array) { if (is_array($array)) { $obj = new StdClass(); foreach ($arr ...
- java Mather 的 group 含义
参考博文: http://blog.csdn.net/java2king/article/details/4395067 明白了group 的 含义 public class Test { pub ...
- random库的常见用法
import random print( random.randint(1,10) ) # 产生 1 到 10 的一个整数型随机数 print( random.random() ) # 产生 0 到 ...
- idea properties编码问题
单个文件设置 全局设置default settings