当前位置:网站首页>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;
}
边栏推荐
- Gartner研究:在中国,混合云的采用已成为主流趋势
- 我想知道股票开户怎么开户?究竟网上开户是否安全么?
- 联想X86服务器重启管理控制器(XClarity Controller)或TSM的方法
- Prototype and prototype chain in JS
- 详解数据治理知识体系
- I want to know how to open a stock account? Is it safe to open an account online?
- 产业互联网中,「小」程序有「大」作为
- Detailed data governance knowledge system
- Nacos configuration center tutorial
- SWT / anr problem - storagemanagerservice stuck
猜你喜欢

SWT / anr problem - storagemanagerservice stuck
![[JS] [Nuggets] get people who are not followers](/img/cc/bc897cf3dc1dc57227dbcd8983cd06.png)
[JS] [Nuggets] get people who are not followers

Densenet network paper learning notes

单片机 MCU 固件打包脚本软件

The latest wechat iPad protocol code obtains official account authorization, etc

CentOS installs multiple versions of PHP and switches

视觉特效,图片转成漫画功能

VirtualBox installation enhancements

Focusing on green and low carbon, data center cooling has entered a new era of "intelligent cooling"

Restcloud ETL practice data row column conversion
随机推荐
Nacos configuration center tutorial
Pulsar的Proxy支持和SNI路由
如何在智汀中实现智能锁与灯、智能窗帘电机场景联动?
如果在小券商办理网上开户安全吗?我的资金会不会不安全?
PCB defect detection based on OpenCV and image subtraction
How to add a condition for an associated table in an SQL statement [null value required or not required]
RestCloud ETL实践之无标识位实现增量数据同步
lavaweb【初识后续问题的解决】
centos 安装多个版本的php并切换
How to open a stock account? Also, is it safe to open an account online?
[2022] Jiangxi postgraduate mathematical modeling scheme and code
Zero foundation self-study SQL course | window function
基于OPENCV和图像减法的PCB缺陷检测
MCU firmware packaging Script Software
522. Longest special sequence II
鼠标悬停效果二
UE4 rendering pipeline learning notes
记一次服务部署失败问题排查
I want to know how to open a stock account? Is it safe to open an account online?
Mouse over effect 10