Codeforces Beta Round #4 (Div. 2 Only) B. Before an Exam dp

B. Before an Exam

题目连接:

http://www.codeforces.com/contest/4/problem/B

Description

Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than minTimei and not more than maxTimei hours per each i-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.

So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours sumTime spent him on preparation, and now he wants to know if he can show his parents a timetable sсhedule with d numbers, where each number sсhedulei stands for the time in hours spent by Peter each i-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all schedulei should equal to sumTime.

Input

The first input line contains two integer numbers d, sumTime (1 ≤ d ≤ 30, 0 ≤ sumTime ≤ 240) — the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following d lines contains two integer numbers minTimei, maxTimei (0 ≤ minTimei ≤ maxTimei ≤ 8), separated by a space — minimum and maximum amount of hours that Peter could spent in the i-th day.

Output

In the first line print YES, and in the second line print d numbers (separated by a space), each of the numbers — amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them.

Sample Input

1 48
5 7

Sample Output

NO

Hint

题意

有n天,你一共学习了m个小时。

这n天每天你必须学习li个小时,但是不能超过ri小时。

问你m个小时能不能合理分配,满足这n天的要求。

如果可以,输出方案。

题解:

直接dp就好了,dp[i][j]表示到了第i天,一共学习了j个小时。

然后记录一下从哪儿转移过来的就好了。

不过数据范围好小,估计怎么做都可以……

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 35;
int n,m;
int l[maxn],r[maxn];
int dp[35][1200],from[35][1200];
void solve(int x,int y)
{if(x!=1)solve(x-1,from[x][y]);printf("%d ",y-from[x][y]);
}
int main()
{scanf("%d%d",&n,&m);for(int i=1;i<=n;i++)scanf("%d%d",&l[i],&r[i]);dp[0][0]=1;for(int i=1;i<=n;i++){for(int j=0;j<1000;j++){if(dp[i-1][j]){for(int k=l[i];k<=r[i];k++){dp[i][j+k]=1;from[i][j+k]=j;}}}}if(dp[n][m]){cout<<"YES"<<endl;solve(n,m);}else cout<<"NO"<<endl;
}

转载于:https://www.cnblogs.com/qscqesze/p/5293318.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/430745.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mbsfn子帧_区分小区内子帧状态的方法、装置以及系统_2008100004878_说明书_专利查询_专利网_钻瓜专利网...

技术领域本发明涉及通信技术领域&#xff0c;尤其涉及一种区分小区内子帧状态的方法、装置以及系统。背景技术第三代组织伙伴计划(3GPP&#xff0c;Third Generation Partnership Projects)于2005年启动了第三代(3G&#xff0c;3rd Generati on)长期演进研究项目(LTE&#xff0…

解决导入myeclipse的项目注释和中文是乱码

1、先说真正解决我所遇到的问题的办法。 用记事本打开——另存为——格式改为UTF-8——保存后在myeclipse就正常显示了。 2、以下是网上找到的办法&#xff0c;试了一些并没有解决问题&#xff0c;但或许是中间必须的步骤吧。 一、更改工作空间编码格式 二、左边更改项目的编码…

fluent17.0中Iso surface设置

Setting up domain-最后一栏creat下拉 JIANZHIYOUDU

POJ 1860 Currency Exchange (SPFA松弛)

题目链接&#xff1a;http://poj.org/problem?id1860 题意是给你n种货币&#xff0c;下面m种交换的方式&#xff0c;拥有第s种货币V元。问你最后经过任意转换可不可能有升值。下面给你货币u和货币v&#xff0c;r1是u到v的汇率&#xff0c;c1是u到v的手续费&#xff0c;同理r2是…

fluent瞬态计算自动保存中cas和data文件全都保存还是只保存data

每一个输出结果同时保存cas文件和data文件 模型树-solution-Caculation activities-Autosave Every-Each time 效果如图&#xff1a; 每一个输出结果只保存data文件不保存cas文件&#xff0c;只有在修改计算设置后自动保存cas文件 模型树-solution-Caculation activities-Onl…

VirtualBox更改默认路径

我这几天想把所有的文件夹都改成英文的&#xff0c;避免运行一些软件的时候因为中文路径发生不必要的错误&#xff0c;怎么移动虚拟机呢&#xff1f;直接修改名字会出错的&#xff0c;网上很多方法什么改注册表&#xff0c;什么运行一大串命令&#xff0c;真的很麻烦&#xff0…

Tecplot如何导入多个DAT文件后激活solution time按钮

先导入CAS&#xff0c;后导入多个DAT文件——错误方式&#xff0c;激活不了。 正确方式&#xff1a;CAS文件和DAT文件同时导入&#xff1a; 此时已激活solution按钮

python修改mp3信息_Python修改MP3文件的方法

本文实例讲述了Python修改MP3文件的方法。分享给大家供大家参考。具体如下&#xff1a;用这个程序修改后的MP3比原来要小一些了&#xff0c;因为一张图片被删除了&#xff0c;起到了给MP3"瘦身"的作用。在一些mp3中&#xff0c;每个都有一张400多K的图片&#xff0c;…

蓝桥杯 无穷分数

无穷分数无穷的分数&#xff0c;有时会趋向于固定的数字。请计算【图1.jpg】所示的无穷分数&#xff0c;要求四舍五入&#xff0c;精确到小数点后5位&#xff0c;小数位不足的补0。请填写该浮点数&#xff0c;不能填写任何多余的内容。<span style"font-size:14px;&quo…

Tecplot如何提取某点数据并导出

Tecplot2018 选中曲线&#xff0c;右键&#xff0c;导出到文件&#xff0c;文件用记事本打开&#xff0c;复制到excel或者origin处理

shell 进入hadoop_Hadoop Shell命令

调用文件系统(FS)Shell命令应使用bin/hadoop fs 的形式。所有的的FS shell命令使用URI路径作为参数。URI格式是scheme://authority/path。对HDFS文件系统&#xff0c;scheme是hdfs&#xff0c;对本地文件系统&#xff0c;scheme是file。其中scheme和authority参数都是可选的&am…

css 水平垂直居中那些事

本文是在参考众大神文章基础上&#xff0c;整理的几个常用方案&#xff0c;另外也掺杂个人的一些猜想&#xff0c;如有不妥&#xff0c;请不吝指出下面开始正题,为了方便验证展示&#xff0c;下面的案例我会直接附上个人验证的源码截图 1. <!doctype html> <html lang…

python 循环指定次数_亮仔的Python之路Day7——Python循环语句

day7&#xff1a;2019-09-01今日学习目的&#xff1a;了解循环语句&#xff0c;使用代码解放劳动力实践是检验真理的唯一标准我们使用代码的最终目的是解放劳动力当你还在复制粘贴累的半死的时候别人随手几行代码就搞定今天学习的是2种循环语句一、什么是循环语句循环语句:可以…

iOS MBProgressHUD 之带底板的加载提示

文章来自&#xff1a;http://blog.csdn.net/ryantang03/article/details/7877120 MBProgressHUD是一个开源项目&#xff0c;实现了很多种样式的提示框&#xff0c;使用上简单、方便&#xff0c;并且可以对显示的内容进行自定义&#xff0c;功能很强大&#xff0c;很多项目中都有…

HEC-RAS如何修改SA/2D Connection的名称

RAS Mapper中打开几何文件&#xff0c;进入编辑模式。

python调试蓝牙适配器_我写了一个查看Android手机的蓝牙模块是否开启的代码。在AVD上调试,因为是电脑,没有蓝牙适配器,可是...

为什么我用到蓝牙手机上的时候&#xff0c;刚打开这个程序&#xff0c;就会停止工作呢&#xff1f;代码如下&#xff0c;代码格式什么没错。publicclassMainActivityextendsActivity{BluetoothAdaptermBluetoothAdapternull;O...为什么我用到蓝牙手机上的时候&#xff0c;刚打开…

CFD何为收敛

文章来自——【小白的CFD之旅】26 何为收敛 - 流沙[胡坤] - 博客园 在CFD计算中&#xff0c;每一个网格上都会存储众多物理量&#xff0c;因此每一个网格上的任一个物理量在计算迭代过程中都会存在一个残差&#xff0c;这意味着在一次迭代过程中&#xff0c;同一物理量在不同的…

如何使用 Microsoft Azure Media Services 现场直播,(Live Streaming) 直播流媒体系统

不久之前&#xff0c;微软公司宣布了 Microsoft Azure Media Services 实时直播服务 ( Live ) 开始进入技术预览阶段&#xff0c;公开接受用户测试。 而这些实时直播服务其实早已被 NBC 运动频道用于多项重大运动赛事直播&#xff0c;包括英超联赛、NHL、周日橄榄球之夜 ( Sund…