From 4131af8aba62c273ff28906b75404264bd443615 Mon Sep 17 00:00:00 2001 From: VidHongqiWu Date: Fri, 27 Oct 2023 21:44:22 -0700 Subject: [PATCH] Add a DP problem named New_Year_and_Hurry --- .DS_Store | Bin 0 -> 10244 bytes Dynamic_Programming/New_Year_and_Hurry.cpp | 35 +++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 .DS_Store create mode 100644 Dynamic_Programming/New_Year_and_Hurry.cpp diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..226ddeb58491a12ccdea858e0bcdb8fa06e89228 GIT binary patch literal 10244 zcmeHM&u`pB6n>NLCf=lJoL|r&Kr2=tq(&hP6j346%_dPB6-b&5AyI!U-nFxF<9HU^ zn{*qc${9}l0dVKU6^Va<3s-Ik{sQ320m1jiUSfL}QE@;h@DjT>^MXu zDsA&BQIUu=TrBmAxb-Rgp0A!V5VgDvDS#(xtU9t$cVxXsH*3fk$QZ~N$QZ~N$Qby4 zFn~Rqi#8Ix|q%bqI zMC7h+9L~IwaE#wXkA3T2`@cmc@MVzl*La|77MhD{%znouq|QFN+EtrAzoC7 z0H`AT4$xN{z67{?@W)51fk;dx|G}GqX3Dk>+ib%|6fP{hOB;x`2+xc#-lT7e{V!td zPXgZo(m>=k5H+ynA*v?s+{UdvEUS_E7gp*=ek=Nt^L4%D*nTiS|GgNvkjoDaX+zqG zcE7qOkE($YwEc?V-Q}lEDV=(^Zq&DI>!_wrElD>pY}fJ>z&0(Y-22dWO?gz2ZP)Y_ zwi>?B3RywcTCc3bteQoti%8H$3S$>(aLaTe>^&TwyAnMfVg%M&{L0_5JRhXx(SR%8&!gB`>347X`jI;_do8q!_&EVi_5qt3CEZu}Z@Tq@u0R$dJ&I+el- zQK|goCso&`x=oQ3g-utwR-sg0k6JXkg6aMqZ6Q@WrqAee`jWn(Z|Mj6g?<-9Vn)0q zu823pJK~18CGLm~(GaGv#lsLk(47LDQes8;czDVwa9H(RN4mUd*;Ys_!Q#HH7UsT69R`+VkV5m6jHB~F^WtsMUP_Y_Q(RL!(^P$=QlCmTaeZCs zTPlfm`X$d~f1GT@rC74bsRRtqQhG@A3B5sh!%4o$sV%9?TqSfTXqDbaGPMx%A#fHQ z(H*2#PKp7ZCDK>g1{h1&7)IJ$Mao=(r7G@om^I6(e!*Q2hEwA{dNP5xxxXZa`AcB( zuxr4py|hP)sV6a}1|v=0mL4Uoa`F{%T@5Llt%e-*M$3$)^*O~qgy*~s^r$37O+{EAx`1cJBj21dFcQ*qtVNS8Nr?!$!l;f9_@GIMd{ zkV5ikBc^meinX{l_tS=T37^{Pr;S8EhltGUWpCg?jJ-TxzI@Vy)3xV~P&_f!^O2$COK*m7E!1-d}LKseQ1ajr?|Nno!g3hAJ z7|0k%Fd%Zv)#VDBx~J>RiZ$_9Cv2aB*S1(@-i1Zt8P9r1~6>2mTzdJ_(?09(7ev gFLMR*G?b{J{P+J1==0euJO3xnzuEc!e4qdS1m*RN^8f$< literal 0 HcmV?d00001 diff --git a/Dynamic_Programming/New_Year_and_Hurry.cpp b/Dynamic_Programming/New_Year_and_Hurry.cpp new file mode 100644 index 00000000..cf8b7031 --- /dev/null +++ b/Dynamic_Programming/New_Year_and_Hurry.cpp @@ -0,0 +1,35 @@ +/*Limak is going to participate in a contest on the last day of the 2016. +The contest will start at 20:00 and will last four hours, exactly until midnight. +There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. +Limak knows it will take him 5·i minutes to solve the i-th problem. +Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. +He needs k minutes to get there from his house, where he will participate in the contest first. +How many problems can Limak solve if he wants to make it to the party? + +Input +The only line of the input contains two integers n and k + +Output +Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier.*/ + +#include +#include +#include +using namespace std; + +int main() +{ + int n, k; + cin >> n >> k; + int time_left = 240 - k; + int dp[time_left + 10]; + memset(dp, 0, sizeof(dp)); + for(int i = 1; i <= n; ++ i) + for(int j = time_left; j >= i * 5; -- j) + { + dp[j] = max(dp[j], dp[j - i * 5] + 1) ; + } + cout << dp[time_left] << endl; + return 0; +} +