日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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

總結

以上是生活随笔為你收集整理的Codeforces Beta Round #4 (Div. 2 Only) B. Before an Exam dp的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。