BZOJ 1037: [ZJOI2008]生日聚会Party(区间dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1037
题意:
思路:
四维数组进行dp,dp[i][j][a][b]表示进行到第i个座位时已经有j个男生了,并且此时男-女的最大值为a,女-男的最大值为b。(这个最大值是由新增的座位后往前计算而得)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int INF = 0x3f3f3f3f;
const int maxn = +; int n, m, k;
int dp[maxn][][][]; int main()
{
//freopen("in.txt","r",stdin);
scanf("%d%d%d",&n,&m,&k);
dp[][][][]=;
for(int i=;i<n+m;i++)
{
for(int j=;j<=n;j++)
{
for(int a=;a<=k;a++)
{
for(int b=;b<=k;b++)
{
if(a+<=k && j+<=n)
dp[i+][j+][a+][max(b-,)]=(dp[i+][j+][a+][max(b-,)] + dp[i][j][a][b])%;
if(b+<=k && i-j+<=m)
dp[i+][j][max(a-,)][b+]=(dp[i+][j][max(a-,)][b+] + dp[i][j][a][b])%;
}
}
}
}
int ans = ;
for(int a=;a<=k;a++)
{
for(int b=;b<=k;b++)
{
ans+=dp[n+m][n][a][b];
ans%=;
}
}
printf("%d\n",ans);
return ;
}
BZOJ 1037: [ZJOI2008]生日聚会Party(区间dp)的更多相关文章
- BZOJ 1037: [ZJOI2008]生日聚会Party [序列DP]
1037: [ZJOI2008]生日聚会Party Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2249 Solved: 1337[Submit] ...
- BZOJ 1037: [ZJOI2008]生日聚会Party 四维DP
1037: [ZJOI2008]生日聚会Party Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1650 Solved: 971[Submit][ ...
- bzoj 1037 [ZJOI2008]生日聚会Party(DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1037 [题意] 一排n男m女,求满足任意连续段男女人数之差不超过k的数目. [思路] ...
- bzoj 1037: [ZJOI2008]生日聚会Party (dp)
dp,但是要顺推容易点 const mm=; var f:..,..,..,..]of longint; n,m,kk,now,sum,i,j,k1,k2:longint; function max( ...
- BZOJ 1037: [ZJOI2008]生日聚会Party( dp )
dp(i, j, a, b)表示选了i个男生, j个女生, 后缀中男生比女生多a(最多), 女生比男生多b(最多). dp(i+1, j, a+1, max(0, b-1)) += dp(i, j, ...
- BZOJ 1037 [ZJOI2008]生日聚会Party
1037: [ZJOI2008]生日聚会Party Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1583 Solved: 936[Submit][ ...
- BZOJ 1037 [ZJOI2008]生日聚会Party(单调DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1037 [题目大意] 现在有n个男生,m个女生排成一行,要求不存在一个区间男女之差大于k ...
- [BZOJ] 1037 [ZJOI2008]生日聚会
Time Limit: 10 Sec Memory Limit: 162 MB Submit: 3007 Solved: 1795 [Submit][Status][Discuss] Descript ...
- BZOJ1037 [ZJOI2008]生日聚会Party 【DP】
1037: [ZJOI2008]生日聚会Party Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2800 Solved: 1654 [Submi ...
随机推荐
- c# Applicatcontext类
Application类(位于System.Windows.Forms命名空间)公开了Run方法,可以调用该方法来调度应用程序进入消息循环.Run方法有三个重载 1.第一个重载版本不带任何参数,比较少 ...
- 开始Nginx的SSL模块
nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/n ...
- table表格超出部分显示省略号
做table表格时,某一列字数比较多,希望超出宽度的部分以省略号显示 设置table的布局 默认automatic 以表格内容显示相应宽度 改成fixed 以表格列宽显示内容 table{ ta ...
- 基于ARM Cortex-M0+ 的Bootloader 参考
源: 基于ARM Cortex-M0+内核的bootloader程序升级原理及代码解析
- Golang字符串解析成数字
package main import ( "strconv" "fmt" ) func main() { // 使用ParseFloat解析浮点数,64是说明 ...
- Introduction to the Standard Directory Layout
Having a common directory layout would allow for users familiar with one Maven project to immediatel ...
- Python概念-上下文管理协议中的__enter__和__exit__
所谓上下文管理协议,就是咱们打开文件时常用的一种方法:with __enter__(self):当with开始运行的时候触发此方法的运行 __exit__(self, exc_type, exc_va ...
- Vue小案例 之 商品管理------学习过滤器 使用过滤器处理日期的格式
代码学习过滤器 过滤器介绍:过滤模型数据,在数据显示前做预处理操作: 内置过滤器:在1.x中,Vue提供了内置过滤器,但是在2.x中已经完全废除: 解决办法: (1)使用第三方库来替代1.x中的内置过 ...
- Eclipse启动参数设置
Eclipse启动参数设置 文件路径:安装目录根路径/eclipse.ini 参数注解: [-debug options -vm javaw.exe] 显示JVM当前内存使用量(注:详见下方<让 ...
- 讨论下python中全局变量的使用
首先看一段代码: A = 0 B = [0] def fun1(A, B): A += 1 B[0] += 1 fun1(A, B) print 'after fun1 %d %s' % (A,B) ...