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 |
贴个c++代码,单数列递推#include <iostream> using namespace std; int sum[12881]; int weight[3402]; int desirability[3402]; int main() { int N, M, w, d; cin >> N >> M; for (int i = 0; i < N; i++) { cin >> weight[i] >> desirability[i]; } for (int f = 0; f < N; f++) { w = weight[f]; d = desirability[f]; for (int i = M; i >= w; i--) { if (sum[i - w] + d > sum[i]) { sum[i] = sum[i - w] + d; } } } cout << sum[M] << '\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