http://codeforces.com/problemset/problem/432/D

题目大意:

给出一栋n层的楼,初始在a层,b层不能去,每次走的距离必须小于当前位置到b的距离,问用电梯来回乱跑得到的序列有多少种。

思路:发现在a的这一侧永远不会到b的另一侧去,因此我们拆开来,只保留a所在的这边,dp:

f[i][j]=Σf[i-1][j] (1<=j<=i+i-1)

然后我们记录前缀和,一边算出sum[1,i-1],另一边用两个指针l,r,每次r移动2,l移动1,算出sum[l,r]

PS:之前用l和r还一边走一边修改真是太傻比了

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
#define ll long long
const ll Mod=;
ll f[][],sum[];
int n,a,b,K,len,pos;
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
ll query(int l,int r){
if (r>len) r=len;
return (((sum[r]-sum[l-])%Mod)+Mod)%Mod;
}
int main(){
n=read();a=read();b=read();K=read();
if (a<b) len=b-,pos=b-a;else len=n-b,pos=a-b;
for (int i=;i<=len;i++)
f[][i]=;
for (int i=;i<=K;i++){
ll cnt=;
for (int j=;j<=len;j++)
f[i%][j]=;
sum[]=;
for (int j=;j<=len;j++)
sum[j]=(sum[j-]+f[(i-)%][j])%Mod;
for (int j=;j<=len;j++){
f[i%][j]=(f[i%][j]+cnt)%Mod;
cnt=(cnt+f[(i-)%][j])%Mod;
}
cnt=;
int r=len+len-,l=len+;
for (int j=len;j>=;j--){
f[i%][j]=(f[i%][j]+query(l,r))%Mod;
r-=;
l--;
}
}
printf("%I64d\n",f[K%][pos]);
return ;
}

Codeforces 479E Riding in a Lift的更多相关文章

  1. Codeforces 479E Riding in a Lift(dp)

    题目链接:Codeforces 479E Riding in a Lift 题目大意:有一栋高N层的楼,有个无聊的人在A层,他喜欢玩电梯,每次会做电梯到另外一层.可是这栋楼里有个秘 密实验室在B层,所 ...

  2. Codeforces 479E. Riding in a Lift (dp + 前缀和优化)

    题目链接:http://codeforces.com/contest/479/problem/E 题意:         给定一个启示的楼层a,有一个不能去的楼层b,对于你可以去的下一个楼层必须满足你 ...

  3. Codeforces 479E Riding in a Lift:前缀和/差分优化dp

    题目链接:http://codeforces.com/problemset/problem/479/E 题意: 有一栋n层的房子. 还有一个无聊的人在玩电梯,每次玩电梯都会从某一层坐到另外一层. 他初 ...

  4. Codeforces 480C Riding in a Lift dp

    主题链接:点击打开链接 意甲冠军: 特定 n a b k 构造一个长度k该序列. 使得序列中 对于随意两个相邻的数 | w[i-1] - w[i] | < | w[i] - b | 且第一个数 ...

  5. Codeforces Round #274 (Div. 1) C. Riding in a Lift 前缀和优化dp

    C. Riding in a Lift Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/480/pr ...

  6. codeforces 480C C. Riding in a Lift(dp)

    题目链接: C. Riding in a Lift time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  7. E. Riding in a Lift(Codeforces Round #274)

    E. Riding in a Lift time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  8. Codeforces Round #274 (Div. 2) Riding in a Lift(DP 前缀和)

    Riding in a Lift time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. cf479E Riding in a Lift

    E. Riding in a Lift time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. U-Boot启动过程完全分析

    U-Boot启动过程完全分析 1.1       U-Boot工作过程 U-Boot启动内核的过程可以分为两个阶段,两个阶段的功能如下: (1)第一阶段的功能 硬件设备初始化 加载U-Boot第二阶段 ...

  2. UNION ALL vs UNION

    一直没意识到它们之间的区别,只知道UNION ALL在性能上优于UNION,忽略一个很重要的区别:UNION会去掉重复的行,而UNION ALL是包括所有行.

  3. 当程序遇到 throw后的处理

    不管你在何处throw出一个exception,后面的代码便不会执行,它会去匹配本层代码中是否有相应的catch语句来捕捉,如果有,则进入此catch块,执行其中的代码.这样这次异常算是处理完了,如果 ...

  4. iOS--创建uiscrollview

    //创建uiscrollview self.PageHeight = self.view.bounds.size.height; self.PageWidth = self.view.bounds.s ...

  5. [Angular 2] Property Binding

    Property Binding is bind property NOT attribute! import {Component, Input, Output, EventEmitter} fro ...

  6. 一些使用Android设备调试功能的注意事项(挖职位)

    华为3C Activity切换动画过热. 当显示器是不是大图easy显现OOM(应用最大大于其他手机内容).因此,调试OOM不要当问题用这个手机,否则,很难发现问题. 小米3 不要调用系统的裁图功能. ...

  7. 2014ACMICPC亚洲区域赛牡丹江现场赛之旅

    下午就要坐卧铺赶回北京了.闲来无事.写个总结,给以后的自己看. 因为孔神要保研面试,所以仅仅有我们队里三个人上路. 我们是周五坐的十二点出发的卧铺,一路上不算无聊.恰巧邻床是北航的神犇.于是下午和北航 ...

  8. Win32函数Sleep的精度测试

    用了三种方法,第一种使用高精度性能计数器:第二种是使用多媒体定时器,另一种是<Windows图形编程>里提供的CPU周期来获取.推荐第一种方式测量: 先看第一种: #include < ...

  9. CentOS6.7 常用操作命令

    centos 安装py环境 1.安装wget工具: yum install wget 2.安装Python-2.7.8: wget --no-check-certificate https://www ...

  10. Form( 表单) 组件

    本节课重点了解 EasyUI 中 Form(表单)组件的使用方法, 这个组件不依赖于任何组件.一. 加载方式表单组件只能在 JS 区域设置,首先定义一张表单.<form id="box ...