hdu 5151 Sit sit sit
http://acm.hdu.edu.cn/showproblem.php?pid=5151
题意:一共有N个椅子,然后有N个学生依次去坐,满足下面三个条件不能坐上去,1:这个椅子旁边有左椅子也有右椅子,2:椅子旁边都有人坐了,3:椅子旁边的椅子颜色不一样。
问如果所有人都坐上去有多少情况。
dp[i][j] 表示区间[i,j]满足的情况数。 这道题是一道区间dp。把一个很大的区间化成多个很小的区间处理。
#include <cstdio>
#include <cstring>
#include <algorithm>
#define mod 1000000007
#define ll long long
using namespace std; int n;
int a[];
ll c[][];
ll dp[][]; void inti()
{
for(int i=; i<=; i++)
{
c[i][]=;
for(int j=; j<=i; j++)
{
c[i][j]=(c[i-][j]+c[i-][j-])%mod;
}
}
} ll get_num(int x,int y)
{
if(x>y) return ;
if(dp[x][y]) return dp[x][y];
if(x==y) return dp[x][y]=;
ll ans=;
for(int i=x+; i<y; i++)
{
if(a[i-]!=a[i+]) continue;
ans+=get_num(x,i-)*get_num(i+,y)%mod*c[y-x][i-x]%mod;
ans%=mod;
}
ans+=get_num(x+,y);
ans%=mod;
ans+=get_num(x,y-);
ans%=mod;
dp[x][y]=ans;
return dp[x][y];
} int main()
{
inti();
while(scanf("%d",&n)!=EOF)
{
memset(dp,,sizeof(dp));
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
}
printf("%lld\n",get_num(,n));
}
return ;
}
hdu 5151 Sit sit sit的更多相关文章
- HDU 5151 Sit sit sit 区间DP + 排列组合
Sit sit sit 问题描述 在一个XX大学中有NN张椅子排成一排,椅子上都没有人,每张椅子都有颜色,分别为蓝色或者红色. 接下来依次来了NN个学生,标号依次为1,2,3,...,N. 对于每个学 ...
- HDU 5151 Sit sit sit 区间dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5151 题解: 有n个椅子,编号为1到n. 现在有n个同学,编号为1到n,从第一个同学开始选择要坐的位 ...
- HDU 1584 蜘蛛牌
题解:纸牌只能移到比其大一的纸牌上,所以移动方向是定的,那么,就只有选择移动先后的问题了,对于决定要移的纸牌,比如1,如果2,3,4都是visited的状态,那么1一定是要移动到5的,因为2,3,4一 ...
- HDU——2723Electronic Document Security(STL map嵌套set做法)
Electronic Document Security Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- hdu 5012 bfs 康托展开
Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- hdu 5150 Sit sit sit
http://acm.hdu.edu.cn/showproblem.php?pid=5151 直接判断是不是素数,然后再注意1就行. #include <cstdio> #include ...
- C++简单使用Jsoncpp来读取写入json文件
一.源码编译 C++操作json字符串最好的库应该就是jsoncpp了,开源并且跨平台.它可以从这里下载. 下载后将其解压到任意目录,它默认提供VS2003和VS2010的工程文件,使用VS2010可 ...
- IMAP收邮件
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 【转】AC算法详解
原文转自:http://blog.csdn.net/joylnwang/article/details/6793192 AC算法是Alfred V.Aho(<编译原理>(龙书)的作者),和 ...
随机推荐
- codechef Cleaning Up 解决问题的方法
After a long and successful day of preparing food for the banquet, it is time to clean up. There is ...
- Enable Access Logs in JBoss 7 and tomcat--转
JBoss 7 is slightly different than earlier version JBoss 5 or 6. The procedure to enable access logs ...
- Java基础知识强化之集合框架笔记35:List练习之产生10个1~20之间的随机数(要求:随机数不能重复)
1. 需求:获取10个1-20之间的随机数,要求不能重复 用数组实现,但是数组的长度是固定的,长度不好确定.所以我们使用集合实现. 分析: • 创建产生随机数的对象 • 创建一个存储随机数的集合. • ...
- 10.7 noip模拟试题
楼[问题背景]zhx 为他的妹子造了一幢摩天楼.[问题描述]zhx 有一幢摩天楼. 摩天楼上面有 M 个观光电梯,每个观光电梯被两个整数
- OBJECT和EMBED标签(转载)
一.介绍: 我们要在网页中正常显示flash内容,那么页面中必须要有指定flash路径的标 签.也就是OBJECT和EMBED标签.OBJECT标签是用于windows平台的IE浏览器的,而EMBED ...
- angularjs kindEditor 中自定义按钮 弹出dialog
1.angular-kindeditor.js 第38行左右加 editorConfig.items = ["placehoder"]; 2.en.js 第234行 placeho ...
- java异步上传图片
第一步:引入需要的js <script src="/res/common/js/jquery.js" type="text/javascript"> ...
- 【POJ3237】【树链剖分】Tree
Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edg ...
- alsa utils工具使用
1.amixer用于控制设置 amixer [-c card] [cmd] ./amixer contents ./amixer cset ./amixer cget 2. aplay ./aplay ...
- 验证视图状态MAC失败解决方案
验证视图状态 mac 失败.如果此应用程序由网络场或群集承载 请确保 machinekey 配置指定了相同的 validationkey 和验证算法.不能在群集中使用 autogenerate. 总是 ...