hdu-6415 计数DP
Nash Equilibrium is an important concept in game theory.
Rikka and Yuta are playing a simple matrix game. At the beginning of the game, Rikka shows an n×m integer matrix A. And then Yuta needs to choose an integer in [1,n], Rikka needs to choose an integer in [1,m]. Let i be Yuta's number and j be Rikka's number, the final score of the game is Ai,j.
In the remaining part of this statement, we use (i,j) to denote the strategy of Yuta and Rikka.
For example, when n=m=3 and matrix A is
If the strategy is (1,2), the score will be 2; if the strategy is (2,2), the score will be 4.
A pure strategy Nash equilibrium of this game is a strategy (x,y) which satisfies neither Rikka nor Yuta can make the score higher by changing his(her) strategy unilaterally. Formally, (x,y) is a Nash equilibrium if and only if:
In the previous example, there are two pure strategy Nash equilibriums: (3,1) and (2,2).
To make the game more interesting, Rikka wants to construct a matrix A for this game which satisfies the following conditions:
1. Each integer in [1,nm] occurs exactly once in A.
2. The game has at most one pure strategy Nash equilibriums.
Now, Rikka wants you to count the number of matrixes with size n×m
InputThe first line contains a single integer t(1≤t≤20), the number of the testcases.
The first line of each testcase contains three numbers n,m and K(1≤n,m≤80,1≤K≤109).
The input guarantees that there are at most 3 testcases with max(n,m)>50.OutputFor each testcase, output a single line with a single number: the answer modulo K.Sample Input
2
3 3 100
5 5 2333
Sample Output
64
1170
OJ-ID:
hdu-6415
author:
Caution_X
date of submission:
20191026
tags:
dp
description modelling:
给定N×M的矩阵A,若该矩阵满足{A(x,y)≥A(i,y) ?i∈[1,n],A(x,y)≥A(x,j) ?j∈[1,m]}且该矩阵元素分别是1~N*M,则称这是矩阵A的一个方案。输入N,M,K,输出N×M矩阵的方案数模K的值。
major steps to solve it:
从最大的数开始依次选择一个位置来存放,第一个数有N×M种放置方法,后面每一个数都必须保证和之前放过的数同一行或者同一列。
首先第一个数会产生一个新行和一个新列,第二个数会产生一个新行或者一个新列,第三个数同第二个数,第四个数及第四个数之后的所有数都分三种情况讨论:
(1)新加入之后产生了一个新行
(2)新加入之后产生了一个新列
(3)既没有产生新行也没有产生新列
设dp[i][j][k],表示已经产生了i个行,j个列,用掉了k个数
那么则:
(1)dp[i][j][k]+=dp[i][j][k-1]*(i*j-i+1)%MOD,没有产生新行或者新列
(2)dp[i][j][k]+=dp[i-1][j][k-1]*(n-i+1)%MOD,产生了新行
(3)dp[i][j][k]+=dp[i][j-1][k-1]*(m-j+1)%MOD,产生了新列
AC code:
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
typedef long long int LL;
LL T, n, m, mod, dp[][][], p;
int main()
{
scanf("%lld", &T);
while(T--) {
scanf("%lld%lld%lld", &n, &m, &mod);
memset(dp, , sizeof dp); p = ;
dp[][][] = n * m % mod;
for(int i=;i<=n*m;i++,p^=) {
for(int j=;j<=n;j++) {
for(int k=;k<=m;k++) {
dp[j][k][p] = ;
if(j * k < i) continue;
dp[j][k][p] = dp[j][k][p^] * (j*k-i+) % mod;
dp[j][k][p] = (dp[j][k][p] + dp[j-][k][p^] * (n-j+) * k) % mod;
dp[j][k][p] = (dp[j][k][p] + dp[j][k-][p^] * (m-k+) * j) % mod;
}
}
}
printf("%lld\n", dp[n][m][p^]);
}
return ;
}
hdu-6415 计数DP的更多相关文章
- 2018多校第九场1004(HDU 6415) DP
本以为是个找规律的题一直没找出来... 题目:给你一个n*m的矩阵和1-n*m个数,问有多少种情况满足纳什均衡的点只有一个.纳什均衡点是指这个元素在所在行和所在列都是最大的. 思路:吉老师直播的思路: ...
- 题解报告:hdu 1028 Ignatius and the Princess III(母函数or计数DP)
Problem Description "Well, it seems the first problem is too easy. I will let you know how fool ...
- HDU 6377 度度熊看球赛 (计数DP)
度度熊看球赛 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- HDU4815/计数DP
题目链接[http://acm.hdu.edu.cn/showproblem.php?pid=4815] 简单说一下题意: 有n道题,每到题答对得分为a[ i ],假如A不输给B的最小概率是P,那么A ...
- HDU5800 To My Girlfriend 背包计数dp
分析:首先定义状态dp[i][j][s1][s2]代表前i个物品中,选若干个物品,总价值为j 其中s1个物品时必选,s2物品必不选的方案数 那么转移的时候可以考虑,第i个物品是可选可可不选的 dp[i ...
- CodeForces 176B Word Cut (计数DP)
Word Cut Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit St ...
- hdu 4123 树形DP+RMQ
http://acm.hdu.edu.cn/showproblem.php? pid=4123 Problem Description Bob wants to hold a race to enco ...
- hdu 4507 数位dp(求和,求平方和)
http://acm.hdu.edu.cn/showproblem.php?pid=4507 Problem Description 单身! 依旧单身! 吉哥依旧单身! DS级码农吉哥依旧单身! 所以 ...
- hdu 3709 数字dp(小思)
http://acm.hdu.edu.cn/showproblem.php?pid=3709 Problem Description A balanced number is a non-negati ...
- [DP之计数DP]
其实说实在 我在写这篇博客的时候 才刚刚草了一道这样类型的题 之前几乎没有接触过 接触过也是平时比赛的 没有系统的做过 可以说0基础 我所理解的计数dp就是想办法去达到它要的目的 而且一定要非常劲非常 ...
随机推荐
- BITCTF-MISC
MISC 以此笔记来记录本菜鸡做misc的历程 签到85 首先看题 提示base85 打开kali,使用python的base64库来解码(内有base85解码) (其实只要输python3即可 我还 ...
- [算法模板]FFT-快速傅里叶变换
[算法模板]FFT-快速傅里叶变换 感谢ZYW聚聚为我们讲解FFT~ 思路 我懒,思路和证明部分直接贴链接: rvalue LSJ-FFT与NTT基础 代码 主要思想是利用了单位根特殊的性质(n次单位 ...
- 为什么老外不愿意用MyBatis?
作者:陈龙 www.zhihu.com/question/309662829 Spring 团队的Josh Long自己在Twitter上做了一个调查.1625次投票,样本量不算大,但也能说明问题.和 ...
- 在nodejs中怎么使用redis缓存组件
redis量个强大的缓存组件,可以部署在windows和linux环境之上,它有五大存储结构,其中有一种为列表list,它可以实现quene和stack的功能,即队列和堆栈的功能. 当然使用先安装py ...
- 简约清新日系你好五月通用PPT模板推荐
模版来源:http://ppt.dede58.com/peixunyanjiang/26488.html
- [javascript string] slice();substr();substring();之间的区别
今天遇到这个问题,发现ぜんぜんわすねまます3个方法,直接上代码吧,[网络版本较多就不注明参考过哪些了 -0- ] var test = 'hello world'; //均一位参数测试 console ...
- SAP会计年度变式
会计年度变式用来确定SAP系统中每个公司的会计记账期间的变式.顾名思议,每个公司的会计年度变式必须与其实际使用的会计年度匹配. 在SAP系统中,每个会计年度最多允许有16个记账期间,其中 ...
- Java日期处理组件joda-time
版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/175 Java日期处理组件joda-time 平常在开发过 ...
- 快速掌握Docker必备基础知识
快速掌握Docker必备基础知识 Docker是时下热门的容器技术,相信作为一名开发人员,你一定听说过或者使用过,很多人会把Docker理解为一个轻量级虚拟机,但其实Docker与虚拟机(VM)是两种 ...
- 记录NodeJs常用工具
安装模块 npm install [-g] module express supervisor:改代码自动重启服务 用法>> supervisor xxx.js 搜索模块 npm sear ...