当前位置:网站首页>Luogu-p1107 [bjwc2008] Lei Tao's kitten
Luogu-p1107 [bjwc2008] Lei Tao's kitten
2022-07-03 19:11:00 【Star_.】
Lei Tao is very loving , In his dorm , Keeping a kitten rescued from injury ( Of course , Such behavior is against the regulations of student dormitory management ). Under his care , The kitten soon recovered , And more lively and lovely .
But one day , Lei Tao returns to his bedroom after class , But I found the kitten missing ! After a search , I found that she was lying on the balcony in a daze at the persimmon tree outside the window …
On the campus of Peking University , There are many persimmon trees , In front of Lei Tao's dormitory , There is N Tree . And this N The height of each persimmon tree is H. The cold of winter gradually enveloped the earth , The leaves on the tree are gradually disappearing , There are only yellow persimmons left , It looks very pleasant . Lei Tao's kitten happens to love persimmons very much , Looking at the persimmons on the tree outside the window , She is very greedy , So I decided to use my agile jumping ability to jump into a tree and eat persimmons .
The kitten can jump from the balcony of the dormitory to the top of any persimmon tree outside the window . after , She can jump down the persimmon tree at her current position every time 1
Unit distance . Of course , The kitten's ability is far more than that , She can also jump between trees . Every time she can jump from the current tree to any other one , In the process , Her height will drop
Delta Unit distance . Every moment , As long as there are persimmons in her position , She can eat . Whole “ Eat persimmons ” Until the kitten falls to the ground .Lei Tao investigated the growth of persimmons on all persimmon trees . He wants to know , The kitten set out from the balcony , How many persimmons can you eat at most ? He knows that writing a program can easily solve this problem , But now he is lazy to write any code . therefore , Now your task is to help Lei Tao write such a program .
Original link
Really excited , Before doing questions, you will get stuck, and then you can understand after reading the solution , This is the first dynamic programming problem I have worked out by myself , It can only be made now. It seems that there is a la carte ..., That label says greed , I read the question for a while , I don't know , How greedy , So try dp To do it , I didn't expect to pass . It's right to brush questions
for the first time , I used a triple loop , The third is from the i Jump from one tree to another and get the most persimmons . then 30 Minute timeout
Code :
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4005;
int dp[N][N];
int main()
{
ios::sync_with_stdio(false);
int n,h,d;
memset(dp,0,sizeof(dp));
cin>>n>>h>>d;
int t,x;
for(int i=1;i<=n;i++){
cin>>t;
for(int j=1;j<=t;j++){
cin>>x;
dp[i][x]++;
}
}
for(int j=h;j>=1;j--)
for(int i=1;i<=n;i++){
int temp = dp[i][j];
for(int k=1;k<=n;k++){
if(i!=k)
dp[i][j] = max(dp[i][j+1],dp[k][j+d]);
}
dp[i][j]+=temp;
}
int ans=0;
for(int i=1;i<=n;i++){
ans = max(ans,dp[i][1]);
}
cout<<ans;
return 0;
}
Although it timed out , But I believe it dp The correctness of the
So I use an array to store the height j The maximum number of persimmons per hour , It becomes a double cycle , It's over
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=4005;
int dp[N][N];
int a[N];
int main()
{
ios::sync_with_stdio(false);
int n,h,d;
memset(dp,0,sizeof(dp));
cin>>n>>h>>d;
int t,x;
for(int i=1;i<=n;i++){
cin>>t;
for(int j=1;j<=t;j++){
cin>>x;
dp[i][x]++;
}
}
for(int j=h;j>=1;j--)
for(int i=1;i<=n;i++){
dp[i][j] = max(dp[i][j+1],a[j+d])+dp[i][j];
a[j] = max(a[j],dp[i][j]);
}
int ans=0;
for(int i=1;i<=n;i++){
ans = max(ans,dp[i][1]);
}
cout<<ans;
return 0;
}
边栏推荐
- In addition to the prickles that pierce your skin, there are poems and distant places that originally haunt you in plain life
- leetcode:556. 下一个更大元素 III【模拟 + 尽可能少变更】
- 2022.02.11
- The most valuable thing
- SQL injection for Web Security (1)
- Today I am filled with emotion
- my. INI file not found
- Day18 - basis of interface testing
- The earliest record
- SSM integration - joint debugging of front and rear protocols (list function, add function, add function status processing, modify function, delete function)
猜你喜欢
![[optics] vortex generation based on MATLAB [including Matlab source code 1927]](/img/9b/b7f462e2ecbff0cee35e7de5c80cf7.jpg)
[optics] vortex generation based on MATLAB [including Matlab source code 1927]

Does SQL always report foreign key errors when creating tables?

Record: pymysql is used in pycharm to connect to the database

leetcode:11. 盛最多水的容器【双指针 + 贪心 + 去除最短板】
![Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext](/img/56/ea61359dd149a49589ba7ad70812a0.jpg)
Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext

What does a really excellent CTO look like in my eyes

The installation path cannot be selected when installing MySQL 8.0.23

Getting started with JDBC

Foundation of ActiveMQ

Simulation scheduling problem of SystemVerilog (1)
随机推荐
Record the errors reported when running fluent in the simulator
Failed to start component [StandardEngine[Catalina]. StandardHost[localhost]. StandardContext
Php based campus lost and found platform (automatic matching push)
2020 intermediate financial management (escort class)
A green plug-in that allows you to stay focused, live and work hard
變化是永恒的主題
Integrated easy to pay secondary domain name distribution system
How does if ($variable) work? [repeat] - how exactly does if ($variable) work? [duplicate]
Flutter network and data storage framework construction-b1
Verilog HDL continuous assignment statement, process assignment statement, process continuous assignment statement
application
我眼中真正优秀的CTO长啥样
22.2.14 -- station B login with code -for circular list form - 'no attribute' - 'needs to be in path selenium screenshot deviation -crop clipping error -bytesio(), etc
Processing of user input parameters in shell script
【光学】基于matlab涡旋光产生【含Matlab源码 1927期】
Web3 credential network project galaxy is better than nym?
C enum contains value - C enum contains value
Record: writing MySQL commands
Scrapy爬虫框架
Add control at the top of compose lazycolumn