当前位置:网站首页>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;
}
边栏推荐
- Ipmitool download address and possible problems during compilation and installation
- Mouse over effect 10
- Xception learning notes
- js 找出两个数组中的重复元素
- How to open a stock account? Also, is it safe to open an account online?
- Leetcode interview question 17.10 Main elements
- Thread Detach
- lavaweb【初识后续问题的解决】
- Comment réaliser la liaison entre la serrure intelligente et la lampe, la scène du moteur de rideau intelligent dans le timing intelligent?
- How do I hide div on Google maps- How to float a div over Google Maps?
猜你喜欢

产业互联网中,「小」程序有「大」作为

Youmeng (a good helper for real-time monitoring of software exceptions: crash) access tutorial (the easiest tutorial for Xiaobai with some foundation)

园区运营效率提升,小程序容器技术加速应用平台化管理

Restcloud ETL practice data row column conversion

RestCloud ETL WebService数据同步到本地

PCB defect detection based on OpenCV and image subtraction

Prototype and prototype chain in JS

Pulsar的Proxy支持和SNI路由

Restcloud ETL WebService data synchronization to local

Applet custom top navigation bar, uni app wechat applet custom top navigation bar
随机推荐
Mnasnet learning notes
【微信小程序開發】樣式匯總
鼠标悬停效果八
Go import self built package
在国内如何买港股的股?用什么平台安全一些?
Restcloud ETL data realizes incremental data synchronization through timestamp
Pycharm 打开远程目录 Remote Host
SSH configuration password free login error: /usr/bin/ssh copy ID: error: no identities found solution
The mobile edge browser cannot open the third-party application
鼠标悬停效果三
基于Pytorch完整的训练一个神经网络并进行验证
Restcloud ETL practice to realize incremental data synchronization without identification bit
js 找出两个数组中的重复元素
SWT / anr problem - storagemanagerservice stuck
Dell server restart Idrac method
How to realize the scene linkage of intelligent lock, lamp and intelligent curtain motor in zhiting?
旷世轻量化网络ShuffulNetV2学习笔记
map数组函数
How to add a condition for an associated table in an SQL statement [null value required or not required]
522. Longest special sequence II