接金币这个c++代码理解不了,求解释
来源:互联网 发布:文华程序交易模型源码 编辑:程序博客网 时间:2024/06/05 12:06
原题链接:http://exercise.acmcoder.com/online/online_judge_ques?ques_id=3009&konwledgeId=134#include <iostream>#include <vector>#include <algorithm>using namespace std;#define INF 0x3f3f3f3ftypedef pair<int, int> p;bool compare(p p1,p p2){return p1.second < p2.second;}int getcoin(vector<p> vec, int pos, int time){int res = 0;for (int i = 0; i < vec.size(); i++){if (vec[i].first == pos&&vec[i].second == time){res++;}if (vec[i].second > time)break;}return res;}int main(){int n;cin >> n;vector<p> vec;for (int i = 0; i < n; i++){p p1;cin >> p1.first >> p1.second;vec.push_back(p1);}int dp[11][2];for (int i = 0; i <= 10; i++){for (int j = 0; j < 2; j++)dp[i][j] =-INF;}dp[5][0] = 0;sort(vec.begin(), vec.end(), compare);int T = vec[vec.size() - 1].second;for (int t = 0; t <=T; t++)for (int j = 0; j <= 10; j++){for (int k = -1; k <= 1; k++){if (dp[j][t%2] == -INF)break;else{dp[j + k][(t + 1) % 2] = max(dp[j + k][(t + 1) % 2],dp[j][t%2]+getcoin(vec,j+k,t+1));//这行理解不了啊}}}int ans = 0;for (int i = 0; i <= 10; i++){ans = ans>dp[i][T % 2] ? ans : dp[i][T % 2];}cout << ans;return 0;}
阅读全文
0 0
- 接金币这个c++代码理解不了,求解释
- 用python写服务器(书上的代码,运行不了,求解释)
- 发这个为了苦金币
- 接金币
- 接金币
- C语言用递归方法求最优次数“挑选伪金币”的问题。
- HTML5+Javascript制作的接金币游戏代码
- 一道关于c的 求解释了
- linux c select函数使用求解释
- 求大神把这个橡皮筋技术代码用类封装!!!!
- 这个怎么实现,求给个思路或代码参考
- 盘子接金币
- 理解不了C语言增1、减1
- 金币
- 金币
- 金币
- 金币
- 求解释!
- git各种状态下撤销修改的方法
- 图的广度优先
- HEEDS MDO 2017.04.2 Win64 & Linux64 2CD+Receiver
- 股票BOLL计算
- Netty百万级推送服务设计要点
- 接金币这个c++代码理解不了,求解释
- Shader编程学习笔记(三)—— 三大主流编程语言 HLSL/GLSL/Cg
- Fragment中getActivity()或getContext()返回null的问题
- 【模板】ST稀疏表
- AndroidManifest 文件合并错误-->tools:replace="android:value"问题
- Communication error. Please use diagnostic mode to check connectivity. You need to have outbound acc
- andriod studio引入hellocharts jar包出现 Cannot resolve symbol LineChartView错误的解决办法
- 字符转ASII码以及大小写之间的转换
- Mybatis中#和$的区别