BT7274

5964

flzj_kl

Misaka_9982

CV工程师_X
handsomepyp
benBiTouzi

MagicMooc

Tw_0

b11

BT7274
1小时前

BT7274
15小时前
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 100010;

int n;
int f[N][3];
int w[N];

int main()
{
cin >> n;
for (int i = 1; i <= n; i ++) cin >> w[i];

memset (f, -0x3f, sizeof f);
f[0][2] = 0;

for (int i = 1; i <= n; i ++)
{
f[i][0] = max(f[i - 1][0], f[i - 1][2] - w[i]);
f[i][1] = f[i - 1][0] + w[i];
f[i][2] = max(f[i - 1][2], f[i - 1][1]);
}

cout << max(f[n][1], f[n][2]) << endl;

return 0;
}


BT7274
16小时前

BT7274
16小时前
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

const int N = 100010, M = 110;

int f[N][M][2];
int n, m;
int w[N];

int main()
{
cin >> n >> m;

for (int i = 1; i <= n; i ++) cin >> w[i];

memset (f, -0x3f, sizeof f);

for (int i = 0; i <= n; i ++) f[i][0][0] = 0;

for (int i = 1; i <= n; i ++)
for (int j = 1; j <= m; j ++)
{
f[i][j][0] = max(f[i - 1][j][0], f[i - 1][j][1] + w[i]);
f[i][j][1] = max(f[i - 1][j][1], f[i - 1][j - 1][0] - w[i]);
}

int res = 0;

for (int i = 0; i <= m; i ++) res = max(res, f[n][i][0]);

cout << res << endl;

return 0;
}


BT7274
19小时前
y总提车了

BT7274
23小时前

dp状态转移一共就这两部分了，两部分都保证正确了就能保证最后得到的状态转移是正确答案了。

BT7274
1天前
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100010;

int w[N];
int f[N][2];

int main()
{
int T;
cin >> T;

while (T --)
{
int n;
cin >> n;

for (int i = 1; i <= n; i ++) cin >> w[i];

f[0][0] = 0, f[0][1] = -1e9;

for (int i = 1;i <= n; i ++)
{
f[i][0] = max(f[i - 1][0], f[i - 1][1]);
f[i][1] = f[i - 1][0] + w[i];
}

int res = max(f[n][0], f[n][1]);

cout << res << endl;

}

return 0;
}


BT7274
1天前

BT7274
1天前

BT7274
1天前
y总已经五天没有更新过b站视频了。 每天早上到十点钟acwing都没有上线。 不知道他在憋什么大招啊。。。