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. 8.2.1.2 How MySQL Optimizes WHERE Clauses MySQL 优化WHERE 子句

    8.2.1.2 How MySQL Optimizes WHERE Clauses MySQL 优化WHERE 子句 本节讨论优化用于处理WHERE子句, 例子是使用SELECT 语句,但是相同的优化 ...

  2. 【转】Android开发工具--android-studio-bundle-141.2288178

    原文网址:http://www.androiddevtools.cn/ AndroidDevTools简介 Android Dev Tools官网地址:www.androiddevtools.cn 收 ...

  3. 【转】Android adb shell操作时出现“ XXX ... Read-only file system”解决办法--不错

    原文网址:http://blog.csdn.net/whu_zhangmin/article/details/25364349 手机连接PC后 adb shell su rm -r /system/a ...

  4. [认知]ClassLoader 认知一二三

    曾经深入了解过ClassLoader,但一直没有时间去总结,现在以参考+自我认识的方式总结一下ClassLoader的相关内容,不能保证100%全,但目前对于一个毛头孩子来说,enough! 首先就要 ...

  5. MD中bitmap源代码分析--SYNC IO和RAID5的补充

    最近在做bwraid的R6的设计工作,需要调研一下bitmap下刷磁盘的IO属性(是否为SYNC IO),还有raid5中bitmap的存储和工作方式. 1.bitmap刷磁盘是否为 SYNC IO? ...

  6. mybatis错误Invalid bound statement (not found) 的解决办法

    <!-- IDEA需要添加一下内容,否则无法找到mapper --> <build> <resources> <resource> <direct ...

  7. SQL-MICK基础

    /*Select语句完整的执行顺序:1.from子句组装来自不同数据源的数据:2.where子句基于指定的条件对记录行进行筛选:3.group by子句将数据划分为多个分组:4.使用聚集函数进行计算: ...

  8. openwrt上网配置的一些理解(四)

    这次要解决的问题是3g上网和wan口上往可以随意切换,当然能够叠加也是好事,不过这不是我关心的.下面还是修改3个文件network,firewall,multiwan.首先在network中加入界面配 ...

  9. SqlServer 笔记

    问题一:这标红色的符号 取掉 一直没有见过标红色的符号,尝试把这些符号粘贴出来到 notepad 发现它是乱码,尝试将它粘贴到sql查询分析器里,发现它显示空白.对于这种数据,一直想着找到这个acsi ...

  10. 设置应用中出现NFC服务,去掉

    还可以在 里面修改