当前位置:网站首页>D - Dire Wolf (interval DP)
D - Dire Wolf (interval DP)
2022-07-26 01:48:00 【to cling】
Problem
Yes n The wolves lined up , Every time you kill a wolf, you get a [ i ] a[i] a[i] The damage of , meanwhile , Each wolf can add b [ i ] b[i] b[i] Point injury . Kill a wolf , The rest of the wolves automatically fill the vacancy . ask : Kill all wolves with the least damage .
Solution
Interval merging : Kill the second k Wolf queen , The intervals on both sides are merged .
State transition equation : d p [ l ] [ r ] = d p [ l ] [ k − 1 ] + d p [ k + 1 ] [ r ] + a [ k ] + b [ l − 1 ] + b [ r + 1 ] dp[l][r] = dp[l][k - 1] + dp[k + 1][r] + a[k] + b[l - 1] + b[r + 1] dp[l][r]=dp[l][k−1]+dp[k+1][r]+a[k]+b[l−1]+b[r+1]
Code
const int N = 2e2 + 5, M = 1e6 + 7;
ll a[N], b[N], f[N][N];
int main()
{
IOS;
int T, cas = 0; cin >> T;
while (T--)
{
int n; cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++)
cin >> b[i];
b[0] = b[n + 1] = 0;
for (int i = 1; i <= n; i++)
f[i][i] = b[i - 1] + b[i + 1] + a[i];
for(int len = 2; len <= n; len++)
for (int l = 1; l <= n - len + 1; l++)
{
int r = l + len - 1;
f[l][r] = inf;
for (int k = l; k <= r; k++)
f[l][r] = min(f[l][r], f[l][k - 1] + f[k + 1][r] + a[k] + b[l - 1] + b[r + 1]);
}
cout << "Case #" << ++cas << ": ";
cout << f[1][n] << endl;
}
return 0;
}
Rethinking
The key is how to merge intervals , I didn't figure out how to merge during the game , I have been writing greedy writing . A lot of time is wasted , Finally, I've been killing time , There is no patience to continue sitting .
边栏推荐
- How uxdb works on multiple processors
- Speech comprehension - structural analysis exercise of fragment reading
- excel中怎么显示数字/英文时间
- Network layer 2 and layer 3 forwarding
- 学习笔记:原码, 反码, 补码
- Spark-SQL中根据年月日显示周几用date_format(date,‘u‘)
- Two stage submission and three stage submission
- Image batch processing Gaussian filter noise reduction + peak signal-to-noise ratio calculation
- [Verilog digital system design (Xia Yuwen) 3 ----- basic concepts of Verilog syntax 1]
- pt-onnx-ncnn转换的问题记录(接yolov5训练)
猜你喜欢

What is cross site scripting (XSS)?

Overview of database stress testing methods

Easyrecovery15 data recovery software with high recovery rate and high download volume

大咖观点+500强案例,软件团队应该这样提升研发效能

The e-commerce project is written in the resume. How to answer it during the interview

Nodejs builds cloud native microservice applications based on dapr, a quick start guide from 0 to 1

Implementation of recommendation system collaborative filtering in spark

Protect syslog servers and devices

Silicon Valley classroom - official account cloud on demand Silicon Valley classroom microservice project practical notes

图像批处理高斯滤波降噪+峰值信噪比计算
随机推荐
Practice sharing of monorepo based on yarn1.x
Shell exercises
Understand Linglong platform unified access service from simple to deep Monet
推荐系统-协同过滤在Spark中的实现
[Verilog digital system design (Xia Yuwen) 3 ----- basic concepts of Verilog syntax 1]
网络之IP地址
"Weilai Cup" 2022 Niuke summer multi school training camp 2 g.[link with monotonic subsequence] block structure
保护系统日志服务器和设备
What should I do when my blog is attacked by hackers?
Mysql_ Note1
“蔚来杯“2022牛客暑期多校训练营2 H.[Take the Elevator] 维护线段
01. MySQL transaction isolation level and concurrent database access
图像批处理高斯滤波降噪+峰值信噪比计算
Server available resources query script
Easyrecovery15 data recovery software with high recovery rate and high download volume
Excuse me, sir. Oracle to PG CDC Oracle, the upper case of the field is the same as that of PG
flutter 下 grpc list没有Setter 方法 ,如何使用相关属性
Analysis of zeromq
NFT market also began to diversify
Guys, the flinksql datahub source table has a field timestamp 16 bits, which is written to ora