Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
使用map时注意重复数据如果使用start或者end作为map的key的话,很方便针对end或者start排序,但是测试数据中会有相同的end或者start,导致出现wrong anwser,后来使用vector<pair<int,int>>的方式记录,sort排序,终于过了 #include <iostream> #include <map> #include <vector> #include <algorithm> using namespace std; int dp[10000001] = {0}; bool cmp(pair<int, int> a, pair<int, int> b) { return a.first < b.first; } int main() { int N, M, R; scanf("%d %d %d" , &N, &M, &R); vector<pair<int, int> > endList; vector<pair<int, int> > timeList; int start, end, effiency; for (int i = 0; i < M; i++) { scanf("%d %d %d", &start, &end, &effiency); endList.push_back(make_pair(end, i)); timeList.push_back(make_pair(start, effiency)); } sort(endList.begin(), endList.end(), cmp); for (vector<pair<int, int> >::iterator iter = endList.begin(); iter != endList.end(); iter++) { int prevDp; end = iter->first; start = timeList[iter->second].first; effiency = timeList[iter->second].second; if (start - R <= 0) prevDp = 0; else prevDp = dp[start-R]; for (int i = end; i <= N; i++) { int e = prevDp + effiency; if (e > dp[i]) dp[i] = e; } } printf("%d\n", dp[N]); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator