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.7 Use of Index Extensions 使用索引扩展

    8.2.1.7 Use of Index Extensions 使用索引扩展 InnoDB 自动扩展每个secondary index 通过添加primary key columns to it,考虑 ...

  2. [LeetCode] 134. Gas Station 解题思路

    There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You ...

  3. 【winform程序】自定义webrowser控件调用IE的版本

    修改注册表: bit: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROW ...

  4. JAVA 将接口的引用指向实现类的对象

    有一个很简单的例子,java.util中的类ArrayList实现了接口List则生成ArrayList对象时可用以下语句. List list=new ArrayList(); 也就是说所有实现了接 ...

  5. cavium octeon 处理器启动总线Bootbus 简介

    cavium octeon 处理器启动总线Bootbus 简介: 韩大卫@吉林师范大学 Boot-bus(启动总线)是cavium octeon处理器的一种用于启动系统的硬件. CPU通过boot b ...

  6. HDOJ 5093 Battle ships 二分图匹配

    二分图匹配: 分别按行和列把图展开.hungary二分图匹配. ... 例子: 4 4 *ooo o### **#* ooo* 按行展开. .. . *ooo o#oo oo#o ooo# **#o ...

  7. Linux Resin 安装配置

    Resin是一个非常流行的application server,对servlet和JSP提供了良好的支持,性能优良,resin自身采用Java语言开发.Resin Pro版本支持缓存和负载均衡,收费最 ...

  8. 二、Solr安装(Tomcat)

    安装环境 Windows 7 64bit Apache-tomcat-8.0.9-windows-x64 Solr-4.9.0 JDK 1.8.0_05 64bit 安装步骤 Tomcat和JDk的安 ...

  9. rhel Linux 网络配置

    --网络配置 vi /etc/sysconfig/network-scripts/ifcfg-eth0 1)DHCPDEVICE=eth0BOOTPROTO=dhcpONBOOT=yes2)静态IP  ...

  10. SQL Profiler工具简介

    一.SQL Profiler工具简介 SQL Profiler是一个图形界面和一组系统存储过程,其作用如下: 图形化监视SQL Server查询: 在后台收集查询信息: 分析性能: 诊断像死锁之类的问 ...