HDU 6415(dp/找規律-2018多校第九場1001)
dp[i][j][k]表示的是放了i個棋子後佔了i行j列的情況,我們容易發現第一個棋子有n * m種情況可以放置,佔用位置是1行1列,而每加多一個棋子就會多增加1行或者1列,一直到所有的行列都佔用完了再把剩下的點放棋子,這樣我就可以從dp[i][j][k]推出dp[i + 1][j + 1][k]、dp[i + 1][j][k + 1]、dp[i + 1][j][k]三種狀態轉移方程做個dp加剪枝剛好卡過
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <list>
#define INF 0x3f3f3f3f
#define maxn 105000
#define maxnn 6000
#define juzheng 300
#define line cout << "-------------------------" << endl;
#define PI acos(-1.0)
#define mem(a,b) memset(a,b,sizeof(a))
#define fill_(a,b,n) fill(a,a + n,b)
#define esp 1e-9
#define ri(n) scanf("%d",&n)
#define ri2(a,b) scanf("%d %d",&a,&b)
#define ri3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define rd(n) scanf("%lf",&n)
#define rd2(a,b) scanf("%lf %lf",&a,&b)
#define rd3(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define rl(n) scanf("%lld",&n)
#define rl2(a,b) scanf("%lld %lld",&a,&b)
#define rl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define rui(n) scanf("%u",&n)
#define rui2(a,b) scanf("%u %u",&a,&b)
#define rui3(a,b,c) scanf("%u %u %u",&a,&b,&c)
#define rs(str) scanf("%s",str)
#define pr(n) cout << n << endl
#define debug(str,x) cout << str << ":" << x << endl
#define ll long long
#define int64 __int64
#define ui unsigned int
using namespace std;
//const ll mod = 1e9 + 7;
//Date:2018-8-20
//Author:HarryBlackCat
ll dp[6403][81][81],n,m,mod;
void init() {
for(ll i = 1;i <= n * m;i++){
for(ll j = 1;j <= n;j++){
for(ll k = 1;k <= m;k++){
dp[i][j][k] = 0;
}
}
}
dp[1][1][1] = n * m;
}
int main() {
//cin.sync_with_stdio(false);//降低cin,cout時間
int t;
while(~ri(t)) {
while(t--) {
rl3(n,m,mod);
init();
ll counter = 0;
for(int i = 1; i < n * m; i++) {
for(int j = 1; j <= n; j++) {
for(int k = 1; k <= m; k++) {
if(max(j,k) > i)
break;
if(!dp[i][j][k])
continue;
if(j < n) {
dp[i + 1][j + 1][k] += dp[i][j][k] * k % mod * (n - j) % mod;
dp[i + 1][j + 1][k] %= mod;
}
if(k < m) {
dp[i + 1][j][k + 1] += dp[i][j][k] * j % mod * (m - k) % mod;
dp[i + 1][j][k + 1] %= mod;
}
if(i < j * k) {
dp[i + 1][j][k] += dp[i][j][k] * (j * k - i) % mod;
dp[i + 1][j][k] %= mod;
}
}
}
}
printf("%lld\n",dp[n * m][n][m] % mod);
}
}
return 0;
}
相關文章
- 【dp+組合數學】hdu 2018 多校第九場 1001 Rikka with Nash Equilibrium hdu 6415UI
- HDU多校第九次 6415 (dp
- 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
- hdu 6415 - DP
- HDU6415(DP)
- HDU 6415 (計數dp)
- HDU 6298 Maximum Multiple(找規律)
- HDU 6415 Rikka with Nash Equilibrium (DP)UI
- HDU6415:Rikka with Nash Equilibrium(dp)UI
- HDU 6415(dp/記憶化搜尋)
- HDU 5795 A Simple Nim (SG函式+打表找規律)函式
- 2024杭電多校第九場
- 打表找規律
- hdu 6415 Rikka with Nash EquilibriumUI
- HDU 2197 本原串 (規律+快速冪)
- 2018 Multi-University Training Contest 9----hdu 6415 Rikka with Nash EquilibriumAIUI
- HUNAN -11566 Graduation Examination(找規律)NaN
- 2020hdu多校8
- 杭電多校第10場 6887 Task Scheduler(DP)
- HDU 6311 - Cover [2018杭電多校聯賽第二場 C](尤拉通路/迴路)
- 2020HDU多校第三場 1005 Little W and Contest
- hdu 2111 Saving HDU (DP)
- HDU6301 Distinct Values (多校第一場1004) (貪心)
- Touring cities (找規律 哈密爾頓迴路)
- LeetCode-6. Z字形變換(找規律)LeetCode
- Gym - 101532A Subarrays Beauty(位操作找規律)
- HDU1024(dp)
- hdu6052 To my boyfriend 2017多校2
- ZOJ Monthly, January 2019 - A Little Sub and Pascal's Triangle(找規律)
- hdu-5384Danganronpa+多校訓練+AC自動機
- HDU 6035 Colorful Tree(樹形DP)
- HDU 1074 Doing Homework(狀壓DP)
- QOJ7789-一道位運算找規律好題
- HDU 1792 - A New Change Problem(規律,最大不能組合數及其個數)
- 8.13(優先佇列貪心維護+打表找規律+對頂堆優先佇列+DFS減枝+貪心dp)佇列
- HDU4652 Dice(期望dp推式子)