k次股票买卖,求助
  • 板块灌水区
  • 楼主Skywalker2187
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/5/5 17:18
  • 上次更新2024/5/5 20:07:40
查看原帖
k次股票买卖,求助
906525
Skywalker2187楼主2024/5/5 17:18

股票买卖

我的代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>

// #define x first
// #define y second

// typedef long long LL;
// typedef std::pair<int,int> PII;

const int N=1e5+10;
// const int inf=1e8+10;
// const int err=-1;
// const double eps=1e-10;
const int M=1e2+10;
const int L=2+10;

using namespace std;

int n,k;
int w[N];

int cnt=0;
int f[N][M][L];

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("monopoly-4.in","r",stdin);
		freopen("monopoly-4.out","w",stdout);
	#endif
	
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&w[i]);
	}

	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=k;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]);
		}
	}

	printf("%d\n",f[n][k][0]);

	return 0;
}

提交后显示RE,求原因

2024/5/5 17:18
加载中...