2018 Multi-University Training Contest 9----hdu 6415 Rikka with Nash Equilibrium
2018 Multi-University Training Contest 9—-hdu 6415 Rikka with Nash Equilibrium
題意:
在一個矩陣中,如果某一個數字是該行該列的最大值,則這個數滿足納什均衡。
要求構造一個n*m的矩陣,裡面填的數字各不相同且範圍是【1,m*n】,問有多少種構造方案。
The 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.
補題寫了三種思路:
不過dfs和dp的思想是一樣的。
考慮三種求情況:
(1)新增一個數,覆蓋的行數+1
(2)新增一個數,覆蓋的列數+1
(3) 新增一個數,覆蓋的行數和列數不變化
1. dfs
但是tle了,據說多交幾次有可能卡過。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m,k;
ll dp[85*85][85][85];
//dfs i x y i表示放置數字的個數,x表示行,y表示列
ll dfs(ll i,ll x,ll y)
{
if(dp[i][x][y]!=-1)return dp[i][x][y];
ll tmp=0;
if(x<n)tmp=tmp+y*(n-x)%k*dfs(i+1,x+1,y)%k%k;
if(y<m)tmp=tmp+x*(m-y)%k*dfs(i+1,x,y+1)%k%k;
if(x*y>i)tmp=tmp+(x*y-i)%k*dfs(i+1,x,y)%k%k;
return dp[i][x][y]=tmp;
}
int main()
{
// ios::sync_with_stdio(false);
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&m,&k);
memset(dp,-1,sizeof(dp));
dp[m*n][n][m]=1;
ll ans=m*n%k*dfs(1,1,1)%k;
printf("%lld\n",ans);
}
return 0;
}
2. DP
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n,m,mod;
ll dp[85*85][85][85];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(dp,0,sizeof(dp));
scanf("%d%d%d",&n,&m,&mod);
dp[1][1][1]=n*m;
for(int i=1;i<m*n;i++)
{
for(int j=1;j<=n;j++)
{
for(int k=1;k<=m;k++)
{
dp[i+1][j+1][k]=dp[i+1][j+1][k]+(n-j)*k*dp[i][j][k];
dp[i+1][j][k+1]=dp[i+1][j][k+1]+(m-k)*j*dp[i][j][k];
if(dp[i+1][j+1][k]>=mod)dp[i+1][j+1][k]%=mod;
if(dp[i+1][j][k+1]>=mod)dp[i+1][j][k+1]%=mod;
ll p=j*k-i;
if(p<=0)continue;
dp[i+1][j][k]=dp[i+1][j][k]+p*dp[i][j][k];
if(dp[i+1][j][k]>=mod)dp[i+1][j][k]%=mod;
}
}
}
printf("%lld\n",dp[n*m][n][m]%mod);
}
return 0;
}
3. 套公式
公式如下:
n!∗m!∗(m∗n)!/(m+n−1)!
n
!
∗
m
!
∗
(
m
∗
n
)
!
/
(
m
+
n
−
1
)
!
<script type="math/tex" id="MathJax-Element-22"> n!*m!*(m*n)!/(m+n-1)!</script>
分母可以消掉,取模就很方便了。
相關文章
- hdu 6415 Rikka with Nash EquilibriumUI
- HDU 6415 Rikka with Nash Equilibrium (DP)UI
- HDU6415:Rikka with Nash Equilibrium(dp)UI
- HDU-6415 Rikka with Nash Equilibrium (DP/找規律)UI
- [DP]HDU6415(2018多校訓練賽第九場 Problem A) Rikka with Nash Equilibrium 題解UI
- 【記憶優化搜尋/dp】HDU - 6415 - 杭電多校第九場 - Rikka with Nash Equilibrium優化UI
- 2018 Multi-University Training Contest 3 - HDU ContestAI
- 【dp+組合數學】hdu 2018 多校第九場 1001 Rikka with Nash Equilibrium hdu 6415UI
- HDU 6039 Gear Up(2017 Multi-University Training Contest 1)AI
- HDU 5235 Friends (2015 Multi-University Training Contest 2 搜尋+剪枝)AI
- HDU-2016 Multi-University Training Contest 3-Sqrt Bo-大數開方AI
- 【HDU5734 2016 Multi-University Training Contest 2A】【公式代入推導】Acperience n維向量各有加減最小模長AI公式
- 【HDU5735 2016 Multi-University Training Contest 2B】【暴力做法 + 折半法】Born Slippy 祖先鏈的最大運算權值AI
- 【HDU5738 2016 Multi-University Training Contest 2E】【平面點數計數 共線判定】Eureka 平面有多少個集合滿足貢獻AI
- The 2024 Hunan Multi-School Programming Training Contest, Round 4NaNAI
- 【DFS】HDU 5423 Rikka with Tree
- North American Invitational Programming Contest 2018
- 2018-01-30 online training 和offline training 在深度學習中什麼意思?AI深度學習
- OpenJDK Nashorn專案介紹JDK
- NFS-Ganasha 高可用配置NFS
- recovery training articleAI
- HDU 5831 Rikka with Parenthesis II (括號匹配)
- #1280 : Rikka with Sequence II [meet int the middle]
- HDU5425Rikka with Tree II(數學期望)
- 2017-2018 ACM-ICPC, NEERC, Southern Subregional ContestACM
- 2017-2018 ACM-ICPC, NEERC, Northern Subregional ContestACM
- 2017-2018 ACM-ICPC, NEERC, Moscow Subregional ContestACM
- NX11 TrainingAI
- online trainingAI
- Training - Problem and Change ManagementAI
- Oracle Training NotesOracleAI
- Oracle Application TrainingOracleAPPAI
- SAP outsource training courseAI
- Crystal report trainingAI
- Spring Training 5SpringAI
- 2018-2019 ACM-ICPC, Asia Seoul Regional Contest——A - CircuitsACMUI
- 2017-2018 ACM-ICPC Southeast Regional Contest (Div. 1)ACMAST
- Java 8 的 Nashorn 指令碼引擎教程Java指令碼