当前位置:网站首页>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;
}
边栏推荐
- Le changement est un thème éternel
- Getting started with JDBC
- 01. Preparation for automated office (free guidance, only three steps)
- Why should we do feature normalization / standardization?
- 【学术相关】顶级论文创新点怎么找?中国高校首次获CVPR最佳学生论文奖有感...
- How can I avoid "div/0!" Errors in Google Docs spreadsheet- How do I avoid the '#DIV/0!' error in Google docs spreadsheet?
- 记录在模拟器中运行flutter时报的错
- Ego planner code parsing Bspline_ Optimizer section (2)
- flask 生成swagger文档
- Record: pymysql is used in pycharm to connect to the database
猜你喜欢
【光学】基于matlab介电常数计算【含Matlab源码 1926期】
Web3 credential network project galaxy is better than nym?
Help change the socket position of PCB part
The online customer service system developed by PHP is fully open source without encryption, and supports wechat customer service docking
leetcode:11. 盛最多水的容器【双指针 + 贪心 + 去除最短板】
User identity used by startup script and login script in group policy
application
Think of new ways
Record: install MySQL on ubuntu18.04
Pan for in-depth understanding of the attention mechanism in CV
随机推荐
Understanding of database architecture
“google is not defined” when using Google Maps V3 in Firefox remotely
EGO Planner代碼解析bspline_optimizer部分(1)
235. The nearest common ancestor of the binary search tree [LCA template + same search path]
Foundation of ActiveMQ
Flask generates swagger documents
Database creation, addition, deletion, modification and query
Free year-end report summary template Welfare Collection
Go home early today
[leetcode] [SQL] notes
Zhengda futures news: soaring oil prices may continue to push up global inflation
變化是永恒的主題
ActiveMQ的基础
Using the visualization results, click to appear the corresponding sentence
[disease identification] machine vision lung cancer detection system based on Matlab GUI [including Matlab source code 1922]
[academic related] how to find the innovation of top papers? Chinese universities won the CVPR Best Student Thesis Award for the first time
【水质预测】基于matlab模糊神经网络水质预测【含Matlab源码 1923期】
硬盘监控和分析工具:Smartctl
Succession of flutter
Analysis of dart JSON encoder and decoder