[hdu6391]Lord Li's problem
首先发现结果与需要改变的具体位置无关,只和需要改变的位置的个数有关,因此设f[i][j]表示选取了i个数字异或结果有j个1,只要分析接下来选择的数和这j个1有几个重合即可:
1. 三个数字全部重合,即$f[i][j+3]+=f[i-1][j]\cdot c(n-j,3)$
2. 有两个数字重合,即$[i][j+1]+=f[i-1][j]\cdot c(n-j,2)\cdot j$
3. 有一个数字重合,即$f[i][j-1]+=f[i-1][j]\cdot (n-j)\cdot c(j,2)$
4. 有0个数字重合,即$f[i][j-3]+=f[i-1][j]\cdot c(j,3)$
然而这并不正确,因为不能重复选择,因此去掉($c(n,3)-(i-2))\cdot f[i-2][j]$,同时这里我们考虑了操作的顺序和操作的位置,再除以$n!\cdot c(n,m)$才是最终答案。

1 #include<bits/stdc++.h>
2 using namespace std;
3 #define mod 19260817
4 int n,m,t,sum,inv[101],fac[101],f[101][101];
5 char s1[101],s2[101];
6 int c(int n,int m){
7 return 1LL*fac[n]*inv[n-m]%mod*inv[m]%mod;
8 }
9 int cc(int n,int m){
10 return 1LL*inv[n]*fac[n-m]%mod*fac[m]%mod;
11 }
12 int main(){
13 inv[0]=inv[1]=fac[0]=fac[1]=1;
14 for(int i=2;i<=40;i++)fac[i]=1LL*fac[i-1]*i%mod;
15 for(int i=2;i<=40;i++)inv[i]=1LL*(mod-mod/i)*inv[mod%i]%mod;
16 for(int i=2;i<=40;i++)inv[i]=1LL*inv[i-1]*inv[i]%mod;
17 while (scanf("%d%d",&n,&m)!=EOF){
18 if ((!n)&&(!m))return 0;
19 scanf("%s%s",s1,s2);
20 sum=0;
21 for(int i=0;i<n;i++)
22 if (s1[i]!=s2[i])sum++;
23 memset(f,0,sizeof(f));
24 f[0][0]=1;
25 for(int i=0;i<=m;i++)
26 for(int j=0;j<=n;j++){
27 if (i>1)f[i][j]=(f[i][j]-f[i-2][j]*(i-1LL)%mod*(c(n,3)-i+2)%mod+mod)%mod;
28 for(int k=-1;k<3;k++)
29 if ((n>j+k)&&(j+k>1))
30 f[i+1][j+2*k-1]=(f[i+1][j+2*k-1]+1LL*c(n-j,k+1)*c(j,2-k)*f[i][j])%mod;
31 }
32 printf("Case #%d: %d\n",++t,1LL*f[m][sum]*cc(n,sum)%mod*inv[m]%mod);
33 }
34 }
[hdu6391]Lord Li's problem的更多相关文章
- 2018 Multi-University Training Contest 7 Solution
A - Age of Moyu 题意:给出一张图,从1走到n,如果相邻两次走的边的权值不同,花费+1, 否则花费相同,求最小花费 思路:用set记录有当前点的最小花费有多少种方案到达,然后最短路 #i ...
- CodeForces 173B Chamber of Secrets spfa
Chamber of Secrets 题目连接: http://codeforces.com/problemset/problem/173/B Description "The Chambe ...
- jstl表达式使用方法
1.jstl.jar servlet.jar支持 2.jsp引入标签库 <%@ taglib prefix="c" uri="http://java.sun.co ...
- Django 2.0 URL
Overview¶ A view is a “type” of Web page in your Django application that generally serves a specific ...
- POJ2594 Treasure Exploration[DAG的最小可相交路径覆盖]
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8301 Accepted: 3 ...
- Django文档阅读-Day3
Django文档阅读-Day3 Writing your first Django app, part 3 Overview A view is a "type" of Web p ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- Stanford Prof. Li Feifei写给她学生的一封信
De-mystifying Good Research and Good Papers By Fei-Fei Li, 2009.03.01 Please remember this: 1000+ co ...
- [LeetCode] The Skyline Problem
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
随机推荐
- ApsNetCore打造一个“最安全”的api接口
Authentication,Authorization 如果公司交给你一个任务让你写一个api接口,那么我们应该如何设计这个api接口来保证这个接口是对外看起来"高大上",&qu ...
- JavaScript兼容性汇总
一般兼容性问都体现到DOM和事件上 只聊ie6+版本浏览器,希望小伙伴们别纠结更低版本浏览器哈^_^ DOM 获取元素 document.getElementsByclassName 不兼容ie6 ...
- Intellij IDEA使用姿势
Intellij IDEA 智能补全的 10 个姿势,太牛逼了.. Intellij Idea非常6的10个姿势
- python的参数传递是值传递还是引用传递??
函数参数传递机制,传值和引用的是什么意思? 函数参数传递机制问题在本质上是调用函数(过程)和被调用函数(过程)在调用发生时进行通信的方法问题.基本的参数传递机制有两种:值传递和引用传递. 值传递(pa ...
- easyDialog 简单、实用的弹出层组件
easyDialog 简单.实用的弹出层组件 使用背景 在完成导师需求时,导师要求寻找比一个layer弹出层组件体积小得多的.最好能嵌入在进HTML代码中而非src引用的弹出层组件,在这个需求下,我找 ...
- 分库分表利器之Sharding Sphere(深度好文,看过的人都说好)
Sharding-Sphere Sharding-JDBC 最早是当当网内部使用的一款分库分表框架,到2017年的时候才开始对外开源,这几年在大量社区贡献者的不断迭代下,功能也逐渐完善,现已更名为 S ...
- Convolutional Neural Network-week1编程题(一步步搭建CNN模型)
Convolutional Neural Networks: Step by Step implement convolutional (CONV) and pooling (POOL) layers ...
- 为什么阿里巴巴开发手册中强制要求 POJO 类使用包装类型?NPE问题防范
封面:学校内的秋天 背景:写这个的原因,也是我这两天凑巧看到的,虽然我一直有 alibaba Java 开发手册,也看过不少次,但是一直没有注意过这个问题 属于那种看过,但又没完全看过 一起来看看吧冲 ...
- [no code][scrum meeting] Alpha 14
项目 内容 会议时间 2020-04-22 会议主题 周中讨论会议 会议时长 45min 参会人员 全体成员 $( "#cnblogs_post_body" ).catalog() ...
- NodeJs安装与环境配置
https://blog.csdn.net/qq_43285335/article/details/90696126 https://www.cnblogs.com/liuqiyun/p/813390 ...