当前位置:网站首页>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;
}
边栏推荐
- Sqlserver query: when a.id is the same as b.id, and the A.P corresponding to a.id cannot be found in the B.P corresponding to b.id, the a.id and A.P will be displayed
- Solution to the problem that the keypad light does not light up when starting up
- Does 1.5.1 in Seata support mysql8?
- Submission lottery - light application server essay solicitation activity (may) award announcement
- picgo快捷键 绝了这人和我的想法 一模一样
- How long will it take to achieve digital immortality? Metacosmic holographic human avatar 8i
- Origin2018 installation and use (sorting)
- 复杂度相关OJ题(LeetCode、C语言、复杂度、消失的数字、旋转数组)
- 程序员职业生涯真的很短吗?
- idea启动Command line is too long问题处理
猜你喜欢
Sweden announced its decision to exclude Huawei 5g equipment, but Huawei has successfully found a new way out
How to use MySQL language for row and column devices?
数据库系统原理与应用教程(001)—— MySQL 安装与配置:MySQL 软件的安装(windows 环境)
动作捕捉系统用于苹果采摘机器人
【Hot100】17. Letter combination of telephone number
广东用电量大跌,说明高新技术产业替代高能耗产业已取得初步成果
vscode 查找 替换 一个文件夹下所有文件的数据
【观察】数字化时代的咨询往何处走?软通咨询的思与行
高端程序员上班摸鱼指南
数据库系统原理与应用教程(003)—— MySQL 安装与配置:手工配置 MySQL(windows 环境)
随机推荐
Problems encountered in IM instant messaging development to maintain heartbeat
Origin2018 installation and use (sorting)
Comment win11 définit - il les permissions de l'utilisateur? Win11 comment définir les permissions de l'utilisateur
The picgo shortcut is amazing. This person thinks exactly the same as me
Research on multi model architecture of ads computing power chip
Golang爬虫框架初探
[open source data] open source data set for cross modal (MRI, Meg, eye movement) human spatial memory research based on virtual reality scenes
Sales management system of lightweight enterprises based on PHP
如何使用phpIPAM来管理IP地址和子网
数据库系统原理与应用教程(006)—— 编译安装 MySQL5.7(Linux 环境)
程序员职业生涯真的很短吗?
In the past six months, it has been invested by five "giants", and this intelligent driving "dark horse" is sought after by capital
The Department came to a Post-00 test paper king who took out 25K. The veteran said it was really dry, but it had been
vim用户自动命令示例
Preliminary study on golang crawler framework
德国iF多项大奖加冕,这副耳机有多强?音珀GTW 270 Hybrid深度评测
Submission lottery - light application server essay solicitation activity (may) award announcement
【Hot100】19. 删除链表的倒数第 N 个结点
毕业后5年,我成为了年薪30w+的测试开发工程师
[每日一氵]Latex 的通讯作者怎么搞