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. iOS 9之New UIKit for International User Interfaces

    金田 Apple一直是注重用户体验的典范,而此次在UI上面,更是做到极致.此次iOS 9的发布能完全支持阿拉伯语.希伯来语等书写和阅读方式为从右向左的语言环境.不仅仅是简单的基础文本,而是支持将界面翻 ...

  2. 使用 APPLY

    原文地址:http://technet.microsoft.com/zh-cn/library/ms175156(v=SQL.105).aspx 使用 APPLY 运算符可以为实现查询操作的外部表表达 ...

  3. [每日一题] 11gOCP 1z0-053 :2013-09-29 Flashback Data Archive ...................................6

    转载请注明出处:http://blog.csdn.net/guoyjoe/article/details/12205299 正确答案:A 具体请参考:http://blog.csdn.net/guoy ...

  4. ie浏览器中 overflow:hidden无作用的解决方案

    原因: overflow:hidden失效 当父元素的直接子元素或者下级子元素的样式拥有position:relative属性时,父元素的overflow:hidden属性就会失效. 我在ie内发现子 ...

  5. 百度全站变https

    今天打开百度首页,突然发现,百度的网址变为 https://www.baidu.com/,如下图: 好嘛,以后再也不怕别人使用抓包工具查看我在百度的搜索数据了.当年的Duck Duck Go就是因为是 ...

  6. mac显示隐藏文件夹

    ~/Library/Preferences/com.apple.finder AppleShowAllFiles -bool true (true 改成 false 就可以不再显示隐藏文件)需要重启, ...

  7. Python发一个GET请求

    # -*- coding: utf-8 -*- try: import httplib2 except ImportError: print('错误:') print(' httplib2这个库没有找 ...

  8. [Linux 小技巧] Ubuntu 14.04 下编译、安装、配置最新开发版 GoldenDict

    1. 背景介绍 GoldenDict 是一款非常优秀的跨平台电子词典软件,支持 StarDict.Babylon 等多种词典.其 PC 版基于 Qt 编写,完全免费.开源且没有广告.GoldenDic ...

  9. linux系统自动执行任务(转)

    开机启动 开机启动应该是我们很经常的需求了,我们常需要在开机时就自动执行某些命令来开启服务,进程等,有了它我们不必再在每次开机时输入同一堆命令. chkconfig命令 使用chkconfig命令可以 ...

  10. springmvc的运行流程分析

    前几篇文章对springmvc讲解的很清楚,大家看下,有问题,我们再一起讨论. 其实springmvc最为重要是它的运行流程,接着,我们来分析一下,其运行过程,废话不多说,看图说话: 分析如下: 1, ...