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
- 2018 Multi-University Training Contest 3 - HDU ContestAI
- 【dp+組合數學】hdu 2018 多校第九場 1001 Rikka with Nash Equilibrium hdu 6415UI
- [DP]HDU6415(2018多校訓練賽第九場 Problem A) Rikka with Nash Equilibrium 題解UI
- 【記憶優化搜尋/dp】HDU - 6415 - 杭電多校第九場 - Rikka with Nash Equilibrium優化UI
- The 2024 Hunan Multi-School Programming Training Contest, Round 4NaNAI
- North American Invitational Programming Contest 2018
- 2018 China Collegiate Programming Contest Final (CCPC-Final 2018)
- Petrozavodsk Winter-2018. Jagiellonian U Contest
- Helvetic Coding Contest 2018 D1
- HDU 6415(dp/找規律-2018多校第九場1001)
- hdu 6415 - DP
- Petrozavodsk Winter-2018. Carnegie Mellon U Contest
- HDU6415(DP)
- Spring Training 5SpringAI
- HDU 6415 (計數dp)
- 2017中國大學生程式設計競賽 - 女生專場(SDKD 2024 Summer Training Contest K2)程式設計AI
- 2018-2019 ACM-ICPC, Asia Seoul Regional Contest——A - CircuitsACMUI
- NX11 TrainingAI
- HDU 5831 Rikka with Parenthesis II (括號匹配)
- 2018-2019 ACM-ICPC, China Multi-Provincial Collegiate Programming ContestACM
- Machine Learning (5) - Training and Testing DataMacAI
- 【HITCON-Training】Lab 12 - SecretGardenAI
- 2024 Autumn Training #2 CG (by hzy)AI
- 2018 BACS Regional Programming Contest C. BACS, Scoundrel Shopkeeper and Contiguous Sequence (模擬)
- HDU 6415(dp/記憶化搜尋)
- 2024 (ICPC) Jiangxi Provincial Contest -- Official Contest
- Mynavi Programming Contest 2021(AtCoder Beginner Contest 201)
- AISing Programming Contest 2021(AtCoder Beginner Contest 202)AI
- HDU多校第九次 6415 (dp
- The 2024 CCPC Shandong Invitational Contest and Provincial Collegiate Programming Contest
- DEEP LEARNING WITH PYTORCH: A 60 MINUTE BLITZ | TRAINING A CLASSIFIERPyTorchAI
- NASH:基於豐富網路態射和爬山演算法的神經網路架構搜尋 | ICLR 2018演算法神經網路架構ICLR
- Toyota Programming Contest 2024#3(AtCoder Beginner Contest 344)
- UNIQUE VISION Programming Contest 2024 Spring(AtCoder Beginner Contest 346)Spring