0

0

Codeforces Round #274 (Div. 2) E. Riding in a Lift(DP)_html/css_WEB-ITnose

php中文网

php中文网

发布时间:2016-06-24 11:55:53

|

1328人浏览过

|

来源于php中文网

原创

Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you're on the floor number a. You are very bored, so you want to take the lift. Floor number b has a secret lab, the entry is forbidden. However, you already are in the mood and decide to make k consecutive trips in the lift.

Let us suppose that at the moment you are on the floor number x (initially, you were on floor a). For another trip between floors you choose some floor with number y (y?≠?x) and the lift travels to this floor. As you cannot visit floor b with the secret lab, you decided that the distance from the current floor x to the chosen y must be strictly less than the distance from the current floor x to floor b with the secret lab. Formally, it means that the following inequation must fulfill: |x?-?y|?|x?-?b|. After the lift successfully transports you to floor y, you write down number y in your notepad.

Your task is to find the number of distinct number sequences that you could have written in the notebook as the result of k trips in the lift. As the sought number of trips can be rather large, find the remainder after dividing the number by 1000000007 (109?+?7).

Input

The first line of the input contains four space-separated integers n, a, b, k (2?≤?n?≤?5000, 1?≤?k?≤?5000, 1?≤?a,?b?≤?n, a?≠?b).

立即学习前端免费学习笔记(深入)”;

Output

Print a single integer ? the remainder after dividing the sought number of sequences by 1000000007 (109?+?7).

Sample test(s)

input

5 2 4 1

output

input

5 2 4 2

output

input

5 3 4 1

output

题意:做电梯,刚开始的时候你在a层,不能到b层,每次你到新的地方的y,必须满足|x-y|

Phidata
Phidata

Phidata是一个开源框架,可以快速构建和部署AI智能体应用

下载

思路:比较容易想到的是dp[i][j]表示第i次到了j层的可能,分情况讨论,例如:当a

#include #include #include #include #include using namespace std;const int mod = 1000000007;const int maxn = 5005;int n, a, b, k, dp[maxn][maxn];int sum[maxn];int main() {	scanf("%d%d%d%d", &n, &a, &b, &k);		memset(dp, 0, sizeof(dp));	if (a < b) {		dp[0][a] = 1;		for (int j = 1; j < b; j++)			sum[j] = sum[j-1] + dp[0][j];		for (int i = 1; i <= k; i++) {			for (int j = 1; j < b; j++)				dp[i][j] = (sum[(b-j-1)/2+j] - dp[i-1][j] + mod) % mod;			sum[0] = 0;			for (int j = 1; j < b; j++)				sum[j] = (sum[j-1] + dp[i][j]) % mod;		}		printf("%d\n", sum[b-1]);	}	else {		dp[0][a] = 1;		for (int j = n; j >= b+1; j--)			sum[j] = sum[j+1] + dp[0][j];		for (int i = 1; i <= k; i++) {			for (int j = b+1; j <= n; j++) 				dp[i][j] = (sum[j-(j-b-1)/2] - dp[i-1][j] + mod) % mod;			sum[0] = 0;			for (int j = n; j >= b+1; j--)				sum[j] = (sum[j+1] + dp[i][j]) % mod;		}		printf("%d\n", sum[b+1]);	}	return 0;}




HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门AI工具

更多
DeepSeek
DeepSeek

幻方量化公司旗下的开源大模型平台

豆包大模型
豆包大模型

字节跳动自主研发的一系列大型语言模型

通义千问
通义千问

阿里巴巴推出的全能AI助手

腾讯元宝
腾讯元宝

腾讯混元平台推出的AI助手

文心一言
文心一言

文心一言是百度开发的AI聊天机器人,通过对话可以生成各种形式的内容。

讯飞写作
讯飞写作

基于讯飞星火大模型的AI写作工具,可以快速生成新闻稿件、品宣文案、工作总结、心得体会等各种文文稿

即梦AI
即梦AI

一站式AI创作平台,免费AI图片和视频生成。

ChatGPT
ChatGPT

最最强大的AI聊天机器人程序,ChatGPT不单是聊天机器人,还能进行撰写邮件、视频脚本、文案、翻译、代码等任务。

相关专题

更多
java连接字符串方法汇总
java连接字符串方法汇总

本专题整合了java连接字符串教程合集,阅读专题下面的文章了解更多详细操作。

7

2026.02.05

java中fail含义
java中fail含义

本专题整合了java中fail的含义、作用相关内容,阅读专题下面的文章了解更多详细内容。

8

2026.02.05

控制反转和依赖注入区别
控制反转和依赖注入区别

本专题整合了控制反转和依赖注入区别、解释、实现方法相关内容。阅读专题下面的文章了解更多详细教程。

11

2026.02.05

钉钉脑图插图教程合集
钉钉脑图插图教程合集

本专题整合了钉钉脑图怎么插入图片、钉钉脑图怎么用相关教程,阅读专题下面的文章了解更多详细内容。

24

2026.02.05

python截取字符串方法汇总
python截取字符串方法汇总

本专题整合了python截取字符串方法相关合集,阅读专题下面的文章了解更多详细内容。

2

2026.02.05

Java截取字符串方法合集
Java截取字符串方法合集

本专题整合了Java截取字符串方法汇总,阅读专题下面的文章了解更多详细操作教程。

1

2026.02.05

java 抽象方法
java 抽象方法

本专题整合了java抽象方法定义、作用教程等内容,阅读专题下面的文章了解更多详细内容。

2

2026.02.05

Eclipse创建jsp文件教程合集
Eclipse创建jsp文件教程合集

本专题整合了Eclipse创建jsp文件、创建jsp项目等等内容,阅读专题下面的文章了解更多详细教程。

26

2026.02.05

java 字符串转数字
java 字符串转数字

本专题整合了java如何字符串转数字相关内容,阅读专题下面的文章了解更多详细教程。

4

2026.02.05

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号