当前位置:网站首页>P2592 [ZJOI2008]生日聚会(dp)
P2592 [ZJOI2008]生日聚会(dp)
2022-07-01 16:16:00 【Harris-H】
P2592 [ZJOI2008]生日聚会(dp)
dp,关键是如何表示男女差的状态。
因此设 d p ( i , j , k , l ) dp(i,j,k,l) dp(i,j,k,l)表示用 i i i个男生, j j j个女生,男生与女生之差最大为 k k k,女生与男生之差最大为 l l l。
然后就四重循环枚举dp即可,枚举当前放的男生还是女生。
时间复杂度: O ( n m k 2 ) O(nmk^2) O(nmk2)
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<bitset>
#include<deque>
#include<ctime>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define ri register int
#define il inline
#define fi first
#define se second
#define mp make_pair
#define pairint pair<int,int>
#define mem0(x) memset((x),0,sizeof (x))
#define mem1(x) memset((x),0x3f,sizeof (x))
il char gc()
{
static const int BS = 1 << 22;
static unsigned char buf[BS], *st, *ed;
if (st == ed) ed = buf + fread(st = buf, 1, BS, stdin);
return st == ed ? EOF : *st++;
}
#define gc getchar
template<class T>void in(T &x)
{
x = 0;
bool f = 0;
char c = gc();
while (c < '0' || c > '9')
{
if (c == '-') f = 1;
c = gc();
}
while ('0' <= c && c <= '9')
{
x = (x << 3) + (x << 1) + (c ^ 48);
c = gc();
}
if (f) x = -x;
}
#undef gc
#define pb push_back
#define int ll
#define md 12345678
int n,m,d;
int f[155][155][22][22];
il int max(const int &a,const int &b)
{
return a>b?a:b;
}
signed main()
{
#ifdef M207
freopen("in.in", "r", stdin);
#endif
in(n),in(m),in(d);
f[0][0][0][0]=1;
for(ri i=0;i<=n;++i)
for(ri j=0;j<=m;++j)
for(ri k=0;k<=d;++k)
for(ri h=0;h<=d;++h)
if(f[i][j][k][h])
{
// printf("%lld %lld %lld %lld: %lld\n",i,j,k,h,f[i][j][k][h]);
int tmp=f[i][j][k][h];
(f[i+1][j][k+1][max(h-1,0)]+=tmp)%=md;
(f[i][j+1][max(k-1,0)][h+1]+=tmp)%=md;
}
int ans=0;
for(ri i=0;i<=d;++i)
for(ri j=0;j<=d;++j)
(ans+=f[n][m][i][j])%=md;
printf("%lld",ans);
return 0;
}
边栏推荐
- Pico,是要拯救还是带偏消费级VR?
- PostgreSQL 存储结构浅析
- ABAP call restful API
- 怎么用MySQL语言进行行列装置?
- Go 语言怎么使用对称加密?
- StoneDB 为国产数据库添砖加瓦,基于 MySQL 的一体化实时 HTAP 数据库正式开源!
- 【SQL语句】请问这边为什么select出了两个上海,查询出了不同的count我想让他变成一个上海,count只显示一个总和
- What is the digital transformation of manufacturing industry
- Principle of motion capture system
- 电脑屏幕变色了怎么调回来,电脑屏幕颜色怎么改
猜你喜欢
Idea start command line is too long problem handling
idea启动Command line is too long问题处理
There is a difference between u-standard contract and currency standard contract. Will u-standard contract explode
怎麼用MySQL語言進行行列裝置?
学会了selenium 模拟鼠标操作,你就可以偷懒点点点了
The sharp drop in electricity consumption in Guangdong shows that the substitution of high-tech industries for high-energy consumption industries has achieved preliminary results
程序员职业生涯真的很短吗?
Nuxt. JS data prefetching
【观察】数字化时代的咨询往何处走?软通咨询的思与行
[SQL statement] Why do you select two Shanghai and query different counts here? I want it to become a Shanghai, and count only displays a sum
随机推荐
數據庫系統原理與應用教程(006)—— 編譯安裝 MySQL5.7(Linux 環境)
从 MLPerf 谈起:如何引领 AI 加速器的下一波浪潮
How does go use symmetric encryption?
Do280 management application deployment - pod scheduling control
Is it reliable to open an account on flush with mobile phones? Is there any potential safety hazard
Vscode find and replace the data of all files in a folder
How to adjust the size of computer photos to what you want
Guide for high-end programmers to fish at work
Go 语言怎么优化重复的 if err != nil 样板代码?
【Hot100】19. 删除链表的倒数第 N 个结点
Origin2018安装与使用(整理中)
Analysis of PostgreSQL storage structure
Talking from mlperf: how to lead the next wave of AI accelerator
ABAP call restful API
如何使用phpIPAM来管理IP地址和子网
学会了selenium 模拟鼠标操作,你就可以偷懒点点点了
Sales management system of lightweight enterprises based on PHP
ThinkPHP kernel work order system source code commercial open source version multi user + multi customer service + SMS + email notification
How to use phpipam to manage IP addresses and subnets
Golang爬虫框架初探