E. Arena dp计数

Posted goto_1600

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了E. Arena dp计数相关的知识,希望对你有一定的参考价值。

link
题意:
给定有n个人,n个人可以取1~x这些取值,n<=500,x<=500 每一轮当场活的人会同时朝所有在场的人开一枪,也就是hp-=1,最后如果全死算是一种方案,问有多少方案。 n < = 500 x < = 500 n<=500 x<=500 n<=500x<=500
思路:
考虑dp, d p [ i ] [ j ] dp[i][j] dp[i][j]代表考虑前i个人,取值<=j的合法方案数,可以发现如果在场一个人是对答案没有贡献的, d p [ i ] [ j ] dp[i][j] dp[i][j]存在两种转移,如果i-1>all in [1,j] 也就是人死光了,每个人有j个可能选择,也就是 j i j^i ji,如果人没死光我们枚举最后一轮死了多少人,也就是 d p [ i ] [ j − i + 1 ] ∗ C ( i , k ) ∗ ( i − 1 ) j dp[i][j-i+1]*C(i,k)*(i-1)^{j} dp[i][ji+1]C(i,k)(i1)j,解释一下, d p [ i ] [ j − i + 1 ] dp[i][j-i+1] dp[i][ji+1]代表活下来人的方案数, C ( i , k ) ∗ ( i − 1 ) j 代 表 死 去 人 的 方 案 数 C(i,k)*(i-1)^{j}代表死去人的方案数 C(i,k)(i1)j
复杂度 O ( N 3 ) O(N^3) O(N3)

// Problem: E. Arena
// Contest: Codeforces - Educational Codeforces Round 116 (Rated for Div. 2)
// URL: https://codeforces.com/contest/1606/problem/E
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC target("avx")
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize("Ofast")
// created by myq
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long ll;
#define x first
#define y second
typedef pair<int,int> pii;
const int N = 510;
const int mod=998244353;
inline int read()
{
	int res=0;
	int f=1;
	char c=getchar();
	while(c>'9' ||c<'0')
	{
		if(c=='-')	f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		res=(res<<3)+(res<<1)+c-'0';
	}
	return res;
 }
 int dp[N][N];
 int c[N][N];
 int kissme[N][N];
 int qmi(int a,int b)
 {
 	int res=1;
 	while(b)
 	{
 		if(b&1)	res=res*1ll*a%mod;
 		b>>=1;
 		a=1ll*a*a%mod;
 	}
 	return res;
 }
signed main()
{
	int n,x;
	cin>>n>>x;
	for(int i=0;i<=500;i++)
		for(int j=0;j<=i;j++)
		{
			if(!j)	c[i][j]=1;
			else	c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
		}
	// cout<<c[5][2]<<endl;
	for(int i=1;i<=500;i++)
		for(int j=0;j<=500;j++)
		kissme[i][j]=qmi(i,j);
	for(int i=2;i<=n;i++)
	{
		for(int j=1;j<=x;j++)
		{
			if(i-1>=j)
			{
				dp[i][j]=kissme[j][i];
			}
			else
			{
				for(int k=2;k<=i;k++)
				{
					dp[i][j]=(dp[i][j]+1ll*dp[k][j-i+1]*c[i][k]%mod*kissme[i-1][i-k])%mod;
				}
				// cout<<i<<" qwq"<<j<<" "<<dp[i][j]<<" "<<kissme[1][0]<<" "<<c[2][2]<<endl;
				dp[i][j]=(dp[i][j]+kissme[i-1][i])%mod;
				
			}
			// cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
		}
	}
	cout<<dp[n][x]<<endl;
	return 0;

}
/**
* In every life we have some trouble
* When you worry you make it double
* Don't worry,be happy.
**/




以上是关于E. Arena dp计数的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 116 (Rated for Div. 2) E. Arena

Educational Codeforces Round 116 (Rated for Div. 2) E. Arena(组合数,DP )

Educational Codeforces Round 116 (Rated for Div. 2) E. Arena(组合数,DP )

2021辽宁省赛 E.生活大爆炸(计数dp)

Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum

E. Not Escaping 题解(dp)