首页 > 气球谜题
头像 我是小一坨
发表于 2024-12-08 21:43:59
D题的暴力优化:https://ac.nowcoder.com/acm/contest/97443/D 我去后面有点急了就没写出来。发现题解是dp,对于我这种蒟蒻来说还是很难写的。 考虑暴力,令a,b,c分别是把大区间染成0,1,2的前缀和。假设这里把大区间分别染色为 0 1 2,枚举i和j为0和1 展开全文
头像 Gooby114514
发表于 2024-12-09 11:16:51
D 气球谜题 官方题解是DP做法,我们这里使用前缀和来做。 由于最后的颜色排列是 的全排列之一,所以我们也是枚举全排列,然后对于每一种排列进行枚举,具体方式如下: 设当前的排列的颜色为 。 定义前缀和数组 表示将前 个气球全部变成 颜色所需的时间,这个递推就可以解决,具体看代码。 可以将最 展开全文
头像 Gnomeshgh112
发表于 2025-03-26 10:08:18
所有的解空间中,一共存在15中状态,每一种状态满足无后效性的性质,可以用动态规划来维护这15种状态,得到最优解。详细状态可见代码注释 #include <bits/stdc++.h> using namespace std; long long Min(long long a, lon 展开全文
头像 蓝乐
发表于 2025-04-15 10:32:46
感谢大佬提供的思路,使用动态规划管理共15种状态,实际上每种状态的前置状态最多会有2种,理解了这一点状态转移方程就不难得出了 const rl = require("readline").createInterface({ input: process.stdin }); var 展开全文
头像 小鹰划船不用桨
发表于 2025-04-11 12:52:00
def solve(n, a_str, t_list): a = list(map(int, a_str)) # 0/1/2 t = t_list # 预处理:计算前缀和 s[0], s[1], s[2] s = [[0] * (n + 1) for _ in r 展开全文
头像 牛客856751393号
发表于 2025-03-05 15:51:52
【Python3】输出和C++版一致,但提交不通过,怀疑是系统问题。纯纯浪费我时间。末尾附赠一个测试用例。 from itertools import permutations n = int(input()) s = input() t = list(map(int, input().split 展开全文
头像 番禺小韭菜
发表于 2025-03-03 21:09:18
#include <algorithm> #include <climits> #include <iostream> #include <vector> using namespace std; int main() { int n; 展开全文
头像 zy还能再战
发表于 2025-03-27 10:01:45
#牛客春招刷题训练营# + 链接假定染色后的气球形如 xxxyyyzzz ,三个区间的右端点分别为i,j,n用 s(x,i) 表示前i个气球中所有原本是x色的染色费用和则有 cost=(s(y,i)+s(z,i))+((s(x,j)-s(x,i))+(s(z,j)-s(z,i)))+((s(x,n) 展开全文
头像 王觊玮
发表于 2025-03-23 17:00:46
#include <algorithm> #include <cstdio> #include <iostream> #include <limits> #include "vector" using namespace std; 展开全文

等你来战

查看全部