讨论 / 小数据好像没问题,大数据用数组不够存怎么办
xve 2018-02-16 16:24:08
点我顶贴 收藏 删除

#include <iostream>

using namespace std;

int main()

{

int N, s[10000] = {0}, p[10000] = {0}, z[10000] = {0};

cin >> N;

//距离

for (int i = 1; i <= N; i++) {

cin >> s[i];

}

//推销消耗的疲劳

for (int i = 1; i <= N; i++) {

cin >> p[i];

}

//算

int now_i = 0,max_i=0,max[10000] = { 0 };

for (int X = 1; X <= N; X++) {

//新的单个疲劳

for (int i = 1; i <= N; i++) {

if (i != now_i&&z[i]>=0) {

if (s[i] > s[max_i])

z[i] =p[i] + 2 * (s[i] - s[max_i]);

else

z[i] = p[i];

}

else

z[now_i] = -1;

}

//选单个疲劳最大

for (int i = 1; i <= N; i++) {

if (z[i] + max[X-1]>= max[X]) {

max[X] = z[i] + max[X - 1];

now_i = i;

if(s[i]>s[max_i])

max_i = i;

}

}

}

for (int i = 1; i <= N; i++)

cout << max[i]<<endl;

}

查看更多回复
提交回复