版本比较
题解:P3257 [JLOI2014] 天天酷跑
正文
增加 29 行删除 3 行
123345677899101112131415161718192021222315 行未改动3940414243444546474849505152535455565758596061# 题意:
糖丸语文阅读理解,这题的语文阅读理解起码给他加了一个难度。有一个地图,你可以吃路过的金币,当然,你可以进行一些跳跃,还可以连跳,虽然有最大连跳次数。求你能吃多少金币。
# 思路:
hyw 题目,看到跳跃高度和连跳次数如此之小的范围,就知道枚举即可,然后使用记忆化搜索,时间复杂度不会炸。看到跳跃高度和连跳次数如此之小的范围,就知道枚举即可,然后使用记忆化搜索,时间复杂度不会炸。
# dfs 部分:可以在初始位置开始 DFS,然后通过记忆化搜索数组记录结果,通过这种方式剪枝可以让复杂度优化很多。然后对于得出的答案,我们将他减去升级所需的费用,就是这个跳跃升级情况所能得到的最大收益了。
# AC code:
```cpp#include<bits/stdc++.h>using namespace std;const int N=100010,M=25;const long long INF=1e18;long long f[M][N][6],res=-INF,res1,res2;int a[M][N],n,m,pay1,pay2,c,h;long long dfs(int x,int y,int num){ if(y>n)return 0; if(a[x][y]==-1)return -INF; if(f[x][y][num]!=-1)return f[x][y][num];15 行未改动 if(x>1)ans=max(ans,dfs(x-1,y+1,num)); f[x][y][num]=ans+a[x][y]; return f[x][y][num];}int main(){ ios::sync_with_stdio(0); cin.tie(0);cout.tie(0); cin>>n>>m>>pay1>>pay2; for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++)cin>>a[i][j]; } for(c=1;c<=5;c++){ for(h=1;h*c<m;h++){ memset(f,-1,sizeof f); long long temp=dfs(1,0,m)-(h-1)*pay1-(c-1)*pay2; if(temp>res)res=temp,res1=h,res2=c; } } if(res>0)cout<<res<<" "<<res2<<" "<<res1; else cout<<"mission failed"; return 0;}```