博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Beta Round #4 (Div. 2 Only) B. Before an Exam dp
阅读量:6209 次
发布时间:2019-06-21

本文共 2535 字,大约阅读时间需要 8 分钟。

B. Before an Exam

题目连接:

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
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"<

转载地址:http://qpzja.baihongyu.com/

你可能感兴趣的文章
基本概念
查看>>
ie6.7.8的hack
查看>>
IOS学习之路九(配置restful webservice 框架restkit)
查看>>
Hadoop: the definitive guide 第三版 拾遗 第十二章 之Hive分区表、桶
查看>>
如何修改 EM12c 中 SYSMAN 用户的密码?
查看>>
[Leetcode] Trapping Rain Water
查看>>
算法练习 (二)
查看>>
程序员谈学习:我为什么要学习Linux?
查看>>
Oracle Essbase入门系列(一)
查看>>
Python编程-Office操作-操作Excel(上)
查看>>
IOCP数据中间件
查看>>
人性的重构
查看>>
SQL Server 排名函数 简单应用
查看>>
条件变量
查看>>
su su- sudo
查看>>
HTML5是否已为实际应用做好准备?
查看>>
大叔手记全集
查看>>
Windows phone 应用开发[7]-MEF For Windows phone
查看>>
卓越软件工程--《微软360度》读后感
查看>>
gcc 之 inline
查看>>