接金币这个c++代码理解不了,求解释

原题链接:http://exercise.acmcoder.com/online/online_judge_ques?ques_id=3009&konwledgeId=134
#include 
#include 
#include 
using namespace std;

#define INF 0x3f3f3f3f

typedef pair p;

bool compare(p p1,p p2){
	return p1.second < p2.second;
}

int getcoin(vector

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

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; }


你可能感兴趣的:(c++)