繁华模拟赛 Vicent坐电梯
/*
n<=5000
这样就不能用O(n)的转移了,而是要用O(1)
的转移。
注意我们每次的转移都来自一个连续的区间,
而且我们是求和
区间求和?
前缀和!
令sum[step][i]表示f[step][1~i]的和
还是以B下侧为例
f[step][i]=sum[step-1][i-1]+sum[step-1][k]-sum[step-1][i] */
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std; typedef long long ll;
const int MAXN = ;
const int MOD = ;
int f[MAXN][MAXN] = {{}};
int n, a, b, k; inline int getnum()
{
char c; int ans = ; bool flag = false;
while ((c = getchar()) == ' ' || c == '\r' || c == '\n');
if (c == '-') flag = true; else ans = c - '';
while ((c = getchar()) >= '' && c <= '') ans = ans * + c - '';
return ans * (flag ? - : );
} inline void add(int &a, int b)
{
ll tmp = (ll)a + b;
if (tmp >= MOD) a = (int)(tmp - MOD);
else if (tmp < ) a = (int)(tmp + MOD);
else a = (int)tmp;
} int main()
{
freopen("lift.in", "r", stdin);
freopen("lift.out", "w", stdout);
n = getnum(); a = getnum(); b = getnum(); k = getnum();
if (fabs(a - b) - == ) { printf("0\n"); return ; }
for (int i = a; i <= n; i++)
f[][i] = ;
for (int step = ; step <= k; step++)
for (int i = ; i <= n; i++)
if (i == b) f[step][i] = f[step][i - ];
else
{
f[step][i] = f[step][i - ];
if (i < b)
{
int x = (b + i) / ;
if ((b + i) % == ) x--;
add(f[step][i], f[step - ][x]);
add(f[step][i], -f[step - ][i]);
add(f[step][i], f[step - ][i - ]);
}
else
{
int x = (b + i) / ;
add(f[step][i], f[step - ][n]);
add(f[step][i], -f[step - ][x]);
add(f[step][i], -f[step - ][i]);
add(f[step][i], f[step - ][i - ]);
}
}
printf("%d\n", f[k][n]);
}
繁华模拟赛 Vicent坐电梯的更多相关文章
- 繁华模拟赛 vicent的字符串
#include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...
- 繁华模拟赛 Vicent与游戏
#include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #i ...
- [繁华模拟赛]Evensgn 剪树枝
Evensgn 剪树枝 题目 繁华中学有一棵苹果树.苹果树有 n 个节点(也就是苹果),n − 1 条边(也就 是树枝).调皮的 Evensgn 爬到苹果树上.他发现这棵苹果树上的苹果有两种:一 种是 ...
- 繁华模拟赛day8 牛栏
/* 标称并没有用到题解中提到的那种奇妙的性质,我们可以证明,正常从1开始走的话,需要T次,如何使这个次数减小?题解中提到一个办法,有一步小于n/t,我们考虑这一步,如果把它匀到左右两步中,则可以减小 ...
- 繁华模拟赛day8 字典序
/* 这个题要我们求一个字典序,字符串给出的顺序,会对字母的字典序前后相对顺序进行限定,如何用来表示这种限定,我们注意到这种一个之后接着一个,只有先输出他前面的才能输出他,很明显就是拓扑排序,最小方案 ...
- 繁华模拟赛day8 科技树
/* 贪心,很明显是越容易升级的越先升级 */ #include<iostream> #include<cstdio> #include<string> #incl ...
- 繁华模拟赛 Vincent的城堡
#include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...
- 繁华模拟赛 Evensgn剪树枝
#include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...
- 繁华模拟赛 Evensgn玩序列
#include<iostream> #include<cstdio> #include<string> #include<cstring> #incl ...
随机推荐
- 在茫茫人海中发现相似的你——局部敏感哈希(LSH)
一.引入 在做微博文本挖掘的时候,会发现很多微博是高度相似的,因为大量的微博都是转发其他人的微博,并且没有添加评论,导致很多数据是重复或者高度相似的.这给我们进行数据处理带来很大的困扰,我们得想办法把 ...
- http技术交流提纲
http技术交流提纲地址:http://lazio10000.github.io/tech/http/#/bored
- 打个酱油,欢迎指正FizzBuzzWhizz(c#)
平民的代码,列表法,凑个热闹,做了简单的测试,太晚了就不写测试用例了 using System; using System.Collections.Generic; using System.Linq ...
- sqlserver日期函数 dateadd,datediff ,datepart ,datename,convert
reference:http://www.cnblogs.com/coconut_zhang/archive/2009/02/02/1382598.html http://blog.itpub.net ...
- JAVA中的NIO(一)
1.IO与NIO IO就是普通的IO,或者说原生的IO.特点:阻塞式.内部无缓冲,面向流. NIO就是NEW IO,比原生的IO要高效.特点:非阻塞.内部有缓存,面向缓冲. 要实现高效的IO操作,尤其 ...
- 大型网站系统架构实践(六)深入探讨web应用集群Session保持
原理 在第三,四篇文章中讲到了会话保持的问题,而且还遗留了一个问题,就是会话保持存在单点故障, 当时的方案是cookie插入后缀,即haproxy指负责分发请求,应用服务自行保持用户会话,如果应 用服 ...
- 每天一个linux命令(23): chown命令
chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID:组可以是组名或者组ID:文件是以空格分开的要改变权限的文件列表,支持通配符.系统管理员经常使用chown命令,在将文件拷贝 ...
- BIEE 配置邮箱服务器
找个免费邮件服务器126或者163的 登录em地址,点击“部署”——>“邮件”——>“锁定并编辑”——>应用——>激活更改——>重新启动以应用最近更改——>重新启动 ...
- 细菌觅食算法-python实现
BFOIndividual.py import numpy as np import ObjFunction class BFOIndividual: ''' individual of bateri ...
- 学习笔记--函数式线段树(主席树)(动态维护第K极值(树状数组套主席树))
函数式线段树..资瓷 区间第K极值查询 似乎不过似乎划分树的效率更优于它,但是如果主席树套树状数组后,可以处理动态的第K极值.即资瓷插入删除,划分树则不同- 那么原理也比较易懂: 建造一棵线段树(权值 ...