hdu6415 记忆化搜索或找规律
Rikka with Nash Equilibrium Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others)
Total Submission(s): Accepted Submission(s): Problem Description
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 [,n], Rikka needs to choose an integer in [,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= and matrix A is
⎡⎣⎢⎢⎤⎦⎥⎥ If the strategy is (,), the score will be ; if the strategy is (,), the score will be . 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:
{Ax,y≥Ai,y ∀i∈[,n]Ax,y≥Ax,j ∀j∈[,m] In the previous example, there are two pure strategy Nash equilibriums: (,) and (,). To make the game more interesting, Rikka wants to construct a matrix A for this game which satisfies the following conditions:
. Each integer in [,nm] occurs exactly once in A.
. The game has at most one pure strategy Nash equilibriums. Now, Rikka wants you to count the number of matrixes with size n×m which satisfy the conditions. Input
The first line contains a single integer t(≤t≤), the number of the testcases. The first line of each testcase contains three numbers n,m and K(≤n,m≤,≤K≤). The input guarantees that there are at most testcases with max(n,m)>. Output
For each testcase, output a single line with a single number: the answer modulo K. Sample Input Sample Output Source
Multi-University Training Contest Recommend
chendu
从大到小填。每次填进去的数都是要在被管住的里面。
#include<iostream>
#include<cstdio>
#include<string.h>
using namespace std;
#define ll long long
ll dp[][][*];
ll n,m,mod;
ll dfs(ll x,ll y,ll z)
{
if(dp[x][y][z]!=-)
return dp[x][y][z];
ll temp=;
if(x<n)
temp=(temp+(y*(n-x)%mod)*dfs(x+,y,z+))%mod;
if(y<m)
temp=(temp+(x*(m-y)%mod)*dfs(x,y+,z+))%mod;
if(x*y>z)
temp=(temp+(x*y-z)%mod*dfs(x,y,z+))%mod;
return dp[x][y][z]=temp;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{ scanf("%lld%lld%lld",&n,&m,&mod);
memset(dp,-,sizeof dp);
dp[n][m][n*m]=;
ll ans=((n*m)%mod*dfs(,,)%mod);
printf("%lld\n",ans); } return ;
}
找规律看https://www.cnblogs.com/solvit/p/9507207.html
hdu6415 记忆化搜索或找规律的更多相关文章
- hdu1331&&hdu1579记忆化搜索(DP+DFS)
这两题是一模一样的``` 题意:给了一系列递推关系,但是由于这些递推很复杂,所以递推起来要花费很长的时间,所以我要编程序在有限的时间内输出答案. w(a, b, c): 如果a,b,c中有一个值小于等 ...
- 牛客国庆集训派对Day2 F、平衡二叉树 【构造+记忆化搜索】
任意门:https://www.nowcoder.com/acm/contest/202/F 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 1048576K,其他语言2097152K6 ...
- 记忆化搜索 codevs 2241 排序二叉树
codevs 2241 排序二叉树 ★ 输入文件:bstree.in 输出文件:bstree.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 一个边长为n的正三 ...
- UVA1629Cake slicing(记忆化搜索)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=51190 紫书P305 题意分析:一个矩形蛋糕上有好多个樱桃,现在要 ...
- ZOJ3795 Grouping(强连通分量+缩点+记忆化搜索)
题目给一张有向图,要把点分组,问最少要几个组使得同组内的任意两点不连通. 首先考虑找出强连通分量缩点后形成DAG,强连通分量内的点肯定各自一组,两个强连通分量的拓扑序能确定的也得各自一组. 能在同一组 ...
- LightOJ1417 Forwarding Emails(强连通分量+缩点+记忆化搜索)
题目大概是,每个人收到信息后会把信息发给他认识的一个人如此下去,问一开始要把信息发送给谁这样看到信息的人数最多. 首先找出图中的SCC并记录每个SCC里面的点数,如果传到一个SCC,那么里面的人都可以 ...
- HDU 1142 A Walk Through the Forest(SPFA+记忆化搜索DFS)
题目链接 题意 :办公室编号为1,家编号为2,问从办公室到家有多少条路径,当然路径要短,从A走到B的条件是,A到家比B到家要远,所以可以从A走向B . 思路 : 先以终点为起点求最短路,然后记忆化搜索 ...
- poj 1085 Triangle War 博弈论+记忆化搜索
思路:总共有18条边,9个三角形. 极大极小化搜索+剪枝比较慢,所以用记忆化搜索!! 用state存放当前的加边后的状态,并判断是否构成三角形,找出最优解. 代码如下: #include<ios ...
- Codevs_1017_乘积最大_(划分型动态规划/记忆化搜索)
描述 http://codevs.cn/problem/1017/ 给出一个n位数,在数字中间添加k个乘号,使得最终的乘积最大. 1017 乘积最大 2000年NOIP全国联赛普及组NOIP全国联赛提 ...
随机推荐
- Vue入门:Vue项目创建及启动
1. 创建Vue项目存放地址 用于存放Vue项目,找个自己处理方便的地方.本人地址:D:\Program Files\Workspace\Vue 2. 创建项目 进入cmd窗口 进入项目存放地址 执行 ...
- 安卓加载网络图片OOM问题解决
前言:次片是上篇后续出现的问题,在网上找了很多博客,越解决越乱,好在最后看了郭霖的博客给了我一点思路 借鉴:http://blog.csdn.net/guolin_blog/article/detai ...
- MySQL5.7 并行复制的学习
MySQL 5.6 基于库级别的并行复制 MySQL5.6的并行复制是库(schema)级别的,从库为每个库(schema)分配一个线程以此来提高复制效率 在MySQL 5.6版本之前,Slave服务 ...
- 基于OpenCV做“三维重建”(3)--相机参数矩阵
通过前面的相机标定,我们能够获得一些参数模型.但是这些相机的参数矩阵到底是什么意思?怎样才能够判断是否正确?误差都会来自哪里?这里就必须要通过具体实验来加深认识.采集带相机参数的图片具有一定难度,幸好 ...
- Guitar Pro中如何添加与删除音轨
Guitar Pro是一款专业的吉他打谱作曲软件,适合每一位热爱吉他并想进一步学习的大家.今天,我们一起来看看Guitar Pro软件写谱时音轨如何添加与删除. Guitar Pro能够同时支持虚拟音 ...
- 清北学堂北京大学冯哲神仙讲课day2
今天讲基础数据结构 首先讲(二叉搜索树) 保证左儿子小于右儿子,那么对于根节点来说.大于根节点的放到右子树递归,小于根节点的放在左子树 相等的呢?某大佬(老师)这么说: 删除的前提是找这个点在哪: 如 ...
- Java中的抽象
什么是抽象类? 如果一个类没有足够的信息去描述一个具体的对象,那么这样的类我们就称它为抽象类.这很好理解,就如同动物是一个很广泛的概念,由于在动物这个类里,我们无法用很详细的信息去描述狗狗这个具体的对 ...
- Slimming Plan
问题 B: Slimming Plan 时间限制: 1 Sec 内存限制: 128 MB 题目描述 Chokudai loves eating so much. However, his docto ...
- 【HNOI 2017】大佬
Problem Description 人们总是难免会碰到大佬.他们趾高气昂地谈论凡人不能理解的算法和数据结构,走到任何一个地方,大佬的气场就能让周围的人吓得瑟瑟发抖,不敢言语.你作为一个 OIer, ...
- 从Scratch到Python——python turtle 一种比pygame更加简洁的实现
从Scratch到Python--python turtle 一种比pygame更加简洁的实现 现在很多学校都开设了Scratch课程,学生可以利用Scratch创作丰富的作品,然而Scratch之后 ...