当前位置:网站首页>Poj-3486-computers[dynamic planning]
Poj-3486-computers[dynamic planning]
2022-07-01 02:46:00 【JackDawn!?】
The original title is
The main idea of the topic
One should ensure that he is n Computers are available every year in the middle of the year , He has two choices every year , Or buy a new computer , Or repair the computer you used before . The money for a new computer is fixed , The money for repairing the computer is m[y][z],y Is the year the computer was purchased ,z Is the year of repair . It is required to find the minimum cost .
Ideas
set up dp[i] Before presentation i There is money needed for computers to be available every year , Put it first j A new computer was replaced in (1<=j<=i), Then the state transition equation is obtained
dp[i] = min(dp[j-1]+c+m[j][i]) (1<=j<=i)
Through this O(n^2) The answer can be obtained through the program of .
AC Code
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 1005;
int c, y;
int m[maxn][maxn];
int dp[maxn];
int main(void)
{
while(~scanf("%d", &c)) {
scanf("%d", &y);
for(int i = 1; i <= y; ++i) {
for(int j = i; j <= y; ++j) {
scanf("%d", &m[i][j]);
}
}
memset(dp, 0x3f, sizeof(dp));
dp[0] = 0;
for(int i = 1; i <= y; ++i) {
for(int j = 1; j <= i; ++j) {
dp[i] = min(dp[i], dp[j-1]+c+m[j][i]);
}
}
printf("%d\n", dp[y]);
}
return 0;
}
边栏推荐
- C language a little bit (may increase in the future)
- js中的原型和原型链
- Here comes the share creators budding talent training program!
- 如果在小券商办理网上开户安全吗?我的资金会不会不安全?
- How to open a stock account? Also, is it safe to open an account online?
- servlet【初识】
- import tensorflow.contrib.slim as slim报错
- 【PR #5 A】双向奔赴(状压DP)
- Mouse over effect IV
- Mnasnet learning notes
猜你喜欢

Mnasnet learning notes

servlet【初识】

js中的原型和原型链
![How to add a condition for an associated table in an SQL statement [null value required or not required]](/img/91/0efbc13597be4dba5b9cf4e8644e35.png)
How to add a condition for an associated table in an SQL statement [null value required or not required]

Small program cloud development -- wechat official account article collection

Pulsar geo replication/ disaster recovery / regional replication

Dell服务器重启iDRAC方法

Optimal Transport系列1

AI edge computing platform - beaglebone AI 64 introduction
![[JS] [Nuggets] get people who are not followers](/img/cc/bc897cf3dc1dc57227dbcd8983cd06.png)
[JS] [Nuggets] get people who are not followers
随机推荐
Mouse over effect II
单片机 MCU 固件打包脚本软件
7_ Openresty installation
Record a service deployment failure troubleshooting
视觉特效,图片转成漫画功能
股票开账户如何优惠开户?还有,在线开户安全么?
Xception学习笔记
js 找出两个数组中的重复元素
js防抖和节流
How to buy Hong Kong shares in China? What platform is safer?
[JS] [Nuggets] get people who are not followers
I want to know how to open a stock account? Is it safe to open an account online?
SAP ALV汇总跟导出Excel 汇总数据不一致
Xception learning notes
[graduation season · advanced technology Er] - summary from graduation to work
Clickhouse eliminates the gap caused by group by
How to add a condition for an associated table in an SQL statement [null value required or not required]
联想X86服务器重启管理控制器(XClarity Controller)或TSM的方法
If I am in Beijing, where is a better place to open an account? In addition, is it safe to open a mobile account?
DenseNet网络论文学习笔记