【题目链接】:http://codeforces.com/problemset/problem/466/D

【题意】



给你n个数字;

让你选择若干个区间;

且这些区间[li,ri];

左端点不能一样;

右端点也不能有一样的;

你能把这些区间内的元素递增1;

问你把所有的n个元素都变成h有多少种方案;.

【题解】



设dp[i][j];

设前i个数字都已经变成h,且有j个区间的左端点没有被匹配的方案数;

每个位置都有些一些选择;

‘-’ 什么都不放

‘]’ 放一个右端点在这个位置;

‘][‘放一个右端点在这,同时立刻开始一个新的区间

‘[]’放一个左端点然后立刻放一个右端点;

‘[‘放一个左端点在这;

①对于a[i]+j==h

则第i个位置有两种选择;

1.’[’ ->则dp[i][j] += dp[i-1][j-1]

2.’-‘->则dp[i][j] += dp[i-1][j];

其他的可以自己试试,会发现不行的

②对于a[i]+j==h-1

则第i个位置有3个选择

1.if (j > 0) ‘][‘->则dp[i][j]+=dp[i-1][j]*j; // 这里的j表示和之前的j个左端点中的某一个匹配;

2.’]’ dp[i][j] += dp[i-1][j+1]*(j+1);//和之前的j+1个左端点中的某一个匹配;

3.’[]’ dp[i][j] += dp[i-1][j];

…其他的都不行的;

最后输出dp[n][0]就好;

③a[i]+j==其他

没有方案;



【Number Of WA】



3(判断dp[i][j]>=MOD之后,要一直减MOD,不能只判断一个if);



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 2000+100;
const LL MOD = 1e9+7; int n,h;
LL dp[N][N],a[N]; void add(LL &a,LL b){
a = a+b;
while (a>=MOD) a-=MOD;
} int main(){
//Open();
Close();
cin >> n >> h;
rep1(i,1,n){
cin >> a[i];
}
dp[1][0] = ((h==a[1])||(h==a[1]+1))?1:0;
dp[1][1] = (h==a[1]+1)?1:0;
rep1(i,2,n){
rep1(j,max((long long) 0,h-a[i]-1),min((long long)i,h-a[i])){
if (a[i]+j==h){
if (j) add(dp[i][j],dp[i-1][j-1]);// [
add(dp[i][j],dp[i-1][j]);// -
//][ x
// ] x
// [] x
}
if (a[i]+j+1==h){
//[ x
// - x
if (j > 0) add(dp[i][j],dp[i-1][j]*j);//][
add(dp[i][j],dp[i-1][j+1]*(j+1));// ]
add(dp[i][j],dp[i-1][j]);//[]
}
}
}
cout << dp[n][0] << endl;
return 0;
}

【codeforces 466D】Increase Sequence的更多相关文章

  1. 【codeforces 602D】Lipshitz Sequence

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  2. 【codeforces 623E】 Transforming Sequence

    http://codeforces.com/problemset/problem/623/E (题目链接) 题意 长度为${n}$的满足前缀按位或为单调递增的${k}$位序列.要求每个位置为${[1, ...

  3. 【CodeForces 622A】Infinite Sequence

    题意 一个序列是, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5....这样排的,求第n个是什么数字. 分析 第n个位置属于1到k,求出k,然后n-i*(i-1)/ ...

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. 【47.40%】【codeforces 743B】Chloe and the sequence

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【codeforces 438D】The Child and Sequence

    [原题题面]传送门 [大致题意] 给定一个长度为n的非负整数序列a,你需要支持以下操作: 1:给定l,r,输出a[l]+a[l+1]+…+a[r]. 2:给定l,r,x,将a[l],a[l+1],…, ...

  7. 【66.47%】【codeforces 556B】Case of Fake Numbers

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【35.29%】【codeforces 557C】Arthur and Table

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【23.33%】【codeforces 557B】Pasha and Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

随机推荐

  1. qt 透明化方法汇总

    一. QT 透明设置 背景,标题栏透明,下级Widget,painter绘出来的(比如,drawtext,drawline)不透明 QWidget window; window.setWindowFl ...

  2. Spring Boot 启动的时候遇到 java.lang.ClassNotFoundException: ch.qos.logback.classic.Level

    在刚开始接触spring boot的时候,想创建一个Hello World 的project. 但是创建完之后,Run as 'Spring Boot APP'的时候遇到这个错误. Level类存在于 ...

  3. C语言实现将一个整形数转换为两个字节16进制

    有时候要用到这个转换,这里记录一下,例如把 int a = 164 转换储存在数组里为 uint8_t b[0]=0x00  , b[1]=0xA4 . 很简单,转换如下: b[0] = a > ...

  4. 封装HttpClient进行http请求与https请求

    一.https忽略证书 /** * 用于进行Https请求的HttpClient * * @author joey * */ public class SSLClient { public stati ...

  5. HDOJ 2189 悼念512汶川大地震遇难同胞——来生一起走 【母函数】

    题意:非常清楚不解释. 策略:如题. 就是个简单的母函数的改变. 这道题做了好久,才明确是那有毛病,还是理解的不够深刻. AC代码: #include<stdio.h> #include& ...

  6. python爬虫 分页获取图片并下载

    --刚接触python2天,想高速上手,就写了个爬虫,写完之后,成就感暴增,用起来顺手多了. 1.源代码 #coding=utf-8 import urllib import re class Pag ...

  7. 嵌入式外部中断控制编程方法论—比較CC2541(51核)和S5PV210(ARM核)

    这是一篇阐述怎样对嵌入式SOC外部中断进行控制编程的方法论文章.希望读者理解本篇文章后.能够具备对市场上全部已经面世和将来面世的嵌入式芯片的外部中断进行控制编程的能力. 笔者原创的技术分享一直都恪守下 ...

  8. 关于iOS7中UIView效果失效问题的解决

    最近想做一个跑马灯的效果.于是写出了例如以下的跑马灯效果的代码...可是调试发现,在iOS6下动画是能够运行的,可是在iOS7下动画并不运行,没有达到预期的效果. [_scrollLabel size ...

  9. bzoj1066: [SCOI2007]蜥蜴(最大流)

    1066: [SCOI2007]蜥蜴 题目:传送门 题解: 哇QTT大佬一眼秒算法...ORT 其实很容易就可以看出来是一道最大流 因为有边的使用限制,那么就可以直接当成是流量来处理嘛 因为是对点进行 ...

  10. Git 时间,将代码托管到GitHub 上

    第一步:在github上创建一个项目,选择所属类型.会自动生成下面的文件. 第二步:使用安卓创建项目 第三步:使用git bash 进入项目目录,通过指令clone到本地 克隆完成后会出现下面的内容 ...