当前位置:网站首页>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;
}
边栏推荐
- Leetcode interview question 17.10 Main elements
- Focusing on green and low carbon, data center cooling has entered a new era of "intelligent cooling"
- Mouse over effect I
- 鼠标悬停效果十
- Use ipmitool to configure BMC network and user information of X86 server
- ANR问题的分析与解决思路
- map数组函数
- [multi source BFS] 934 Shortest Bridge
- [PR # 5 A] two way running (state pressure DP)
- Restcloud ETL practice to realize incremental data synchronization without identification bit
猜你喜欢

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

MnasNet学习笔记

Evaluation of the entry-level models of 5 mainstream smart speakers: apple, Xiaomi, Huawei, tmall, Xiaodu, who is better?

Restcloud ETL WebService data synchronization to local

Dell server restart Idrac method

Lenovo x86 server restart management controller (xclarity controller) or TSM method

Proxy support and SNI routing of pulsar

RestCloud ETL实践之无标识位实现增量数据同步

The operation efficiency of the park is improved, and the application platform management of applet container technology is accelerated

如何在智汀中实现智能锁与灯、智能窗帘电机场景联动?
随机推荐
Why are strings immutable in many programming languages? [repeated] - why are strings immutable in many programming languages? [duplicate]
CentOS installs multiple versions of PHP and switches
Applet custom top navigation bar, uni app wechat applet custom top navigation bar
ipmitool下载地址和编译安装时可能出现的问题
在国内如何买港股的股?用什么平台安全一些?
Lenovo x86 server restart management controller (xclarity controller) or TSM method
我想知道股票开户怎么开户?究竟网上开户是否安全么?
如何在智汀中實現智能鎖與燈、智能窗簾電機場景聯動?
Pulsar 主题压缩
小程序自定义顶部导航栏,uni-app微信小程序自定义顶部导航栏
如果我在北京,到哪里开户比较好?另外,手机开户安全么?
[graduation season · advanced technology Er] - summary from graduation to work
SWT / anr problem - storagemanagerservice stuck
Zero foundation self-study SQL course | window function
鼠标悬停效果十
Map array function
Mouse over effect IV
Thread Detach
pycharm 软件deployment 灰色 无法点
基于Pytorch完整的训练一个神经网络并进行验证