[luoguP2904] [USACO08MAR]跨河River Crossing(DP)
f[i] 表示送前 i 头牛过去再回来的最短时间
f[i] = min(f[i], f[j] + sum[i - j] + m) (0 <= j < i)
——代码
#include <cstdio>
#include <iostream> const int MAXN = , INF = ;
int n, m;
int sum[MAXN], f[MAXN]; inline long long read()
{
long long x = , f = ;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -;
for(; isdigit(ch); ch = getchar()) x = (x << ) + (x << ) + ch - '';
return x * f;
} inline int min(int x, int y)
{
return x < y ? x : y;
} int main()
{
int i, j, x;
n = read();
m = read();
sum[] = m;
for(i = ; i <= n; i++)
{
x = read();
sum[i] = x + sum[i - ];
}
for(i = ; i <= n; i++)
{
f[i] = INF;
for(j = ; j < i; j++) f[i] = min(f[i], f[j] + sum[i - j] + m);
}
printf("%d\n", f[n] - m);
return ;
}
[luoguP2904] [USACO08MAR]跨河River Crossing(DP)的更多相关文章
- [USACO08MAR]跨河River Crossing dp
题目描述 Farmer John is herding his N cows (1 <= N <= 2,500) across the expanses of his farm when ...
- bzoj1617 / P2904 [USACO08MAR]跨河River Crossing
P2904 [USACO08MAR]跨河River Crossing 显然的dp 设$f[i]$表示运走$i$头奶牛,木筏停在未过河奶牛一侧所用的最小代价 $s[i]$表示一次运$i$头奶牛到对面的代 ...
- 【洛谷】P2904 [USACO08MAR]跨河River Crossing(dp)
题目描述 Farmer John is herding his N cows (1 <= N <= 2,500) across the expanses of his farm when ...
- P2904 [USACO08MAR]跨河River Crossing
题目描述 Farmer John is herding his N cows (1 <= N <= 2,500) across the expanses of his farm when ...
- 洛谷—— P2904 [USACO08MAR]跨河River Crossing
https://www.luogu.org/problem/show?pid=2904 题目描述 Farmer John is herding his N cows (1 <= N <= ...
- 【洛谷2904/BZOJ1617】[USACO08MAR]跨河River Crossing(动态规划)
题目:洛谷2904 分析: 裸dp-- dp方程也不难想: \(dp[i]\)表示运\(i\)头牛需要的最短时间,\(sum[i]\)表示一次运\(i\)头牛(往返)所需的时间,则 \[dp[i]=m ...
- 洛谷 P2904 [USACO08MAR]跨河River Crossing
题目 动规方程 f[i]=min(f[i],f[i−j]+sum) 我们默认为新加一头牛,自占一条船.想象一下,它不断招呼前面的牛,邀请它们坐自己这条船,当且仅当所需总时间更短时,前一头奶牛会接受邀请 ...
- USACO River Crossing
洛谷 P2904 [USACO08MAR]跨河River Crossing https://www.luogu.org/problem/P2904 JDOJ 2574: USACO 2008 Mar ...
- BZOJ 1617: [Usaco2008 Mar]River Crossing渡河问题( dp )
dp[ i ] = max( dp[ j ] + sum( M_1 ~ M_( i - j ) ) + M , sum( M_1 ~ M_i ) ) ( 1 <= j < i ) 表示运 ...
随机推荐
- bzoj 1045: [HAOI2008] 糖果传递【瞎搞】
感觉我的智商可能不够写题解,就直接截了hzwer的blog 地址http://hzwer.com/2656.html #include<iostream> #include<cstd ...
- codevs1297 硬币(背包dp,方案数)
1297 硬币 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 我们知道即使是同一种面值的硬币,它们的重量也有可能不一样, ...
- Django day 38 结算中心,支付中心,计算价格方法
一:结算中心 二:支付中心 三:计算价格方法
- GG_Logs 日志类库封装使用说明
3.6.GG_Logs 日志类库封装使用说明 GG_Logs类库项目,Nuget安装log4net 添加代码配置代码: [assembly: log4net.Config.XmlConfigurato ...
- [NOI2004]cashier 郁闷的出纳员
Description OIER公司是一家大型专业化软件公司,有着数以万计的员工.作为一名出纳员,我的任务之一便是统计每位员工的工资.这本来是一份不错的工作,但是令人郁闷的是,我们的老板反复无常,经常 ...
- 状压DP UVA 10817 Headmaster's Headache
题目传送门 /* 题意:学校有在任的老师和应聘的老师,选择一些应聘老师,使得每门科目至少两个老师教,问最少花费多少 状压DP:一看到数据那么小,肯定是状压了.这个状态不好想,dp[s1][s2]表示s ...
- 莫队算法/二分查找 FZU 2072 Count
题目传送门 题意:问区间内x的出现的次数分析:莫队算法:用一个cnt记录x的次数就可以了.还有二分查找的方法 代码: #include <cstdio> #include <algo ...
- C#---数据库访问通用类、Access数据库操作类、mysql类 .
//C# 数据库访问通用类 (ADO.NET)using System;using System.Collections.Generic;using System.Text;using System. ...
- sublime 3 最新注册码
http://9iphp.com/web/html/sublime-text-3-license-key.html
- springboot与dubbo整合遇到的坑
整合环境: dubbo 2.6.2 springboot 2.1.5 遇到的问题:服务一直无法注册到zookeeper注册中心 项目结构: 使用application.properties文件: 配置 ...