这数据怎么定义动态规划数组?没办法,只能打爆搜了,50分。。。。
查看原帖
这数据怎么定义动态规划数组?没办法,只能打爆搜了,50分。。。。
383782
StarPatrick楼主2021/4/24 11:03
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n, book[3005];
struct e
{
	int w, r;
}a[3005];
int dfs(int low)
{
	int ans = 0;
	for (int p=1;p<=n;p++)
	{
		if (!book[p]&&a[p].w>low)
		{
			book[p] = 1;
			ans = max(ans, dfs(low+a[p].r)+a[p].w-low);
			book[p] = 0;
		}
	}
	return ans;
}
int main()
{
	cin>>n;
	for (int p=1;p<=n;p++)
	{
		cin>>a[p].w>>a[p].r;
	}
	cout<<dfs(0);
    return 0;
}
2021/4/24 11:03
加载中...