HDU6415(DP)
本來不想用滾動shuz陣列,但是時間太久了,是滾動陣列的三倍,記憶體是兩百倍。還有就是學到用函式來進行資料相加與取模。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#define mem(a,x) memset(a,x,sizeof(a))
#define s1(x) scanf("%d",&x)
#define s2(x,y) scanf("%d%d",&x,&y)
#define s3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s4(x,y,z,k) scanf("%d%d%d%d",&x,&y,&z,&k)
#define ff(a,n) for(int i = 0 ; i < n; i++) scanf("%d",a+i)
#define tp(x) printf("x = %d\n",x)
#define ansp(x) printf("%d\n",x)
#define ls 2*rt
#define rs 2*rt+1
#define lson ls,L,mid
#define rson rs,mid+1,R
#define ll long long
using namespace std;
typedef pair<int,int> pii;
//inline ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&(-x);return res;}
//inline void add(int x,int d){while(x<=n)c[x]+=d,x+=x&(-x);}
//int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b);}
const ll inf = 0x3f3f3f3f;
const int mx = 0;
int mod,n,m;
int dp[2][85][85];
void add(int &a, ll b){
a = (a+b)%mod;
}
int main(){
// freopen("F:\\in.txt","r",stdin);
int T=10; scanf("%d",&T);
while(T--){
s3(n,m,mod);
int sum = n*m;
mem(dp,0);
dp[0][1][1] = sum;
int now = 0,ne;
for(int k = 2; k <= sum; k++){
ne = now^1;
mem(dp[ne],0);
for(int i = 1; i <= n; i++)
for(int j = 0; j <= m ;j++){
int te = dp[now][i][j];
if(te){
//dp[ne][i][j] += 1LL*(i*j-k+1)*te %mod;
add(dp[ne][i][j],1LL*(i*j-k+1)*te);
//if(dp[ne][i][j]>=mod)
// dp[ne][i][j] -= mod;
// dp[ne][i+1][j] += 1ll*(n-i)*j*te%mod;
add(dp[ne][i+1][j],1ll*(n-i)*j*te);
//if(dp[ne][i+1][j]>=mod)
// dp[ne][i+1][j] -= mod;
//dp[ne][i][j+1] += 1ll*i*(m-j)*te%mod;
add(dp[ne][i][j+1],1ll*i*(m-j)*te);
//if(dp[ne][i][j+1]>=mod)
//dp[ne][i][j+1] -= mod;
}
}
now = ne;
}
printf("%d\n",dp[now][n][m]);
}
return 0;
}
相關文章
- HDU6415:Rikka with Nash Equilibrium(dp)UI
- [DP]HDU6415(2018多校訓練賽第九場 Problem A) Rikka with Nash Equilibrium 題解UI
- dp 套 dp(dp of dp)小記
- DP套DP
- [DP] 數位DP
- 【DP】Educational DP Contest
- dp套dp 隨寫
- 【DP】區間DP入門
- dp
- [DP] DP最佳化總結
- 序列 DP
- dp板子
- DP(一)
- six[Dp]
- DP動態規劃-爬塔(雙層dp)動態規劃
- 動態 DP
- 換根 DP
- 線性dp
- dp加練
- DP 詳解
- 機率DP
- scientifically practice DP
- dp02
- 樹形DP
- dp洩露
- 數位 dp
- 換根dp
- 狀壓DP
- 區間dp
- 樹形DP!
- 揹包DP
- 狀壓 dp
- hdu 6415 - DP
- [狀壓dp] 最短Hamilton路徑(模板題+狀壓dp)
- 計數類 DP
- 連續段DP
- 20240918:DP選做
- 預設型 DP