繁华模拟赛 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 ...
随机推荐
- Common Lisp编译程序的小技巧
这几天开始玩Common Lisp,遇上了一个有意思的问题,CL一般是解释运行,也有实现可以编译生成字节码(fas文件).我正在用的两种CL实现是SBCL和CLISP,前者是我从<实用Commo ...
- ModernUI教程:使用预定义的页面布局
Modern UI for WPF自带了一组页面布局.Modern UI page是继承自control控件的,Page通过是通过ModernWindow.MenuLinkGroups属性来引用显示在 ...
- 多个相同name的文本输入框,输入其中一个后,使剩下的不能输入值
可以用blur或keyup事件响应: 实现一: <body> <input type="text" id="AfterOtOt1" name= ...
- js中的运动
缓慢隐藏与出现 效果: 鼠标移至分享上黄色区域自动向左隐藏. <!DOCTYPE html> <html> <head> <title></tit ...
- js中定时器的使用
1.setInterval <!DOCTYPE html> <html> <head> <title>json</title> <sc ...
- Java基础-静态代理与动态代理比较
JAVA的静态代理与动态代理比较 静态代理类: 由程序员创建或由特定工具自动生成源代码,再对其编译.在程序运行前,代理类的.class文件就已经存在了.动态代理类: 在程序运行时,运用反射机制动态创建 ...
- 【poj1144】 Network
http://poj.org/problem?id=1144 (题目链接) 题意 求无向图的割点. Solution Tarjan求割点裸题.并不知道这道题的输入是什么意思,也不知道有什么意义= =, ...
- USACO 3.3 fence 欧拉回路
题意:求给定图的欧拉回路(每条边只走一次) 若欧拉回路存在,图中只可能有0个or2个奇数度的点. 求解时,若有奇数度的点,则必须从该点开始.否则可以从任一点开始 求解过程:dfs //主程序部分 # ...
- Bzoj3893 [Usaco2014 Dec]Cow Jog
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 302 Solved: 157 Description The cows are out exerci ...
- Android Studio使用教程
http://blog.csdn.net/ryantang03/article/details/8948037 http://blog.csdn.net/ryantang03/article/deta ...