【cf】EPIC Institute of Technology Round Summer 2024(Div. 1 + Div. 2)题解 C - D

C. Basil’s Garden(dp)

发现最后一个变为 0 的一定是第一个,对于每一个位置而言,如果它后面的位置没变为 0 ,那么它就不可能变为 0,所以它变为 0 的时刻最小应该是在它后一个位置变为 0 的时刻加 1,如果这个位置太高的话,就需要 a[i] 个时间变为 0,所以当前位置变为 0 的时刻就是二者取最大值

设计 dp[i] 表示第 i 个位置变为 0 的时刻,有转移方程:dp[i] = max(dp[i + 1] + 1, a[i])

#include <bits/stdc++.h>

using namespace std;

#define int long long
using i64 = long long;

typedef pair<int, int> PII;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<int, PII> PIII;
typedef pair<int, pair<int, bool>> PIIB;

const int N = 1e5 + 10;
const int maxn = 1e6 + 10;
const int mod = 998244353;
const int mod1 = 954169327;
const int mod2 = 906097321;
const int INF = 0x3f3f3f3f3f3f3f3f;

void solve()
{
	int n;
	cin >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i ++ ) cin >> a[i];
	reverse(a.begin() + 1, a.end());
	vector<int> ans(n + 1);
	ans[1] = a[1];
	for (int i = 2; i <= n; i ++ ) ans[i] = max(ans[i - 1] + 1, a[i]);
	cout << ans[n] << '\n';
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
	{
		solve();
	}
}

D. World is Mine(dp)

关于博弈问题的一般思路:

首先思考二者分别的最优策略:

Alice 一定是能取小的就取小的

Bob 需要取一定的数使得 Alice 没法取这个数

设计 dp[i][j] 表示 Bob 在前 i 种数里选完了 j 种(注意是种不是个)的时候需要进行的操作次数

如果不取第 i + 1 种的话, dp[i + 1][j + 1] 等于 dp[i][j + 1]

如果要取第 i + 1 种,首先需要满足一个条件,即 dp[i][j] + 第i+1种数字的个数 <= i - j,因为要保证 Alice 的操作次数比 Bob 多,在满足该条件的基础下,dp[i + 1][j + 1] 等于 min(dp[i + 1][j + 1], dp[i][j] + 第i+1种数字的个数)

#include <bits/stdc++.h>

using namespace std;

#define int long long
using i64 = long long;

typedef pair<int, int> PII;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<int, PII> PIII;
typedef pair<int, pair<int, bool>> PIIB;

const int N = 1e5 + 10;
const int maxn = 1e6 + 10;
const int mod = 998244353;
const int mod1 = 954169327;
const int mod2 = 906097321;
const int INF = 0x3f3f3f3f3f3f3f3f;

void solve()
{
	int n;
	cin >> n;
	vector<int> cnt(n + 1);
	for (int i = 0; i < n; i ++ )
	{
		int x; cin >> x;
		cnt[x] ++ ;
	}
	vector<int> v;
	for (int i = 1; i <= n; i ++ )
	{
		if (cnt[i] > 0) v.push_back(cnt[i]);
	}
	int m = v.size();
	vector<vector<int>> dp(m + 1, vector<int>(m + 1, INF));
	for (int i = 0; i <= m; i ++ ) dp[i][0] = 0;
	for (int i = 0; i < m; i ++ )
	{
		for (int j = 0; j < i; j ++ )
		{
			dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j + 1]);
			if (dp[i][j] + v[i] <= i - j)
			{
				dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + v[i]);
			}
		}
	}
	int ans = INF;
	for (int i = 0; i <= m; i ++ )
	{
		if (dp[m][i] != INF) ans = min(ans, m - i);
	}
	cout << ans << '\n';
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
	{
		solve();
	}
}
  • 12
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
根据提供的引用内容,Codeforces Round 511 (Div. 1)是一个比赛的名称。然而,引用内容中没有提供与这个比赛相关的具体信息或问题。因此,我无法回答关于Codeforces Round 511 (Div. 1)的问题。如果您有关于这个比赛的具体问题,请提供更多的信息,我将尽力回答。 #### 引用[.reference_title] - *1* [Codeforces Round 860 (Div. 2)题解](https://blog.csdn.net/qq_60653991/article/details/129802687)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Codeforces Round 867 (Div. 3)(A题到E题)](https://blog.csdn.net/wdgkd/article/details/130370975)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Codeforces Round 872 (Div. 2)(前三道](https://blog.csdn.net/qq_68286180/article/details/130570952)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Texcavator

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值