DFS #4WA 86 答案118输出119求助
查看原帖
DFS #4WA 86 答案118输出119求助
658787
newtocpp楼主2023/5/16 22:39

我的代码

// P2690
#include <bits/stdc++.h>
using namespace std;
int t, w, tmp, mem[1005][35][2]; //mem记忆化
bool ids[1005]; //ids每分钟苹果的位置,0第一棵树,1第二棵树
int DFS(int m, int move, bool side) //m当前分钟 move移动的步数 side当前位置
{
	if(m == t) return 0;
	if(move == w + 1) return -1; //和第16行的+1抵消
	if(mem[m][move][side] != -1) return mem[m][move][side]; //记忆判断
	if(ids[m] == side) //如果不用动就能接苹果
	{
		mem[m][move][side] = DFS(m + 1, move, side) + 1;
		return mem[m][move][side];
	}
	mem[m][move][side] = max(DFS(m + 1, move + 1, !side) + 1, DFS(m + 1, move, side));
	return mem[m][move][side];
}
int main()
{
	fill(mem[0][0], mem[0][0] + 70350, -1);
	cin >> t >> w;
	for(int x = 0; x < t; x++)
	{
		cin >> tmp;
		ids[x] = tmp - 1;
	}
	cout << DFS(0, 0, 0);
	return 0;
}

#4WA没过 正确答案118 程序输出119 求助大佬

2023/5/16 22:39
加载中...