嘟嘟嘟

我dp真是太弱了,这么简单dp都不会。

令dp[i]表示前 i 头牛头被遮住了的最低成本。则dp[i] = min{dp[i], dp[j - 1] + c[a[i] - a[j] + 1]} (1 <= j <= i)

然后别忘了预处理后缀最小值。

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const ll INF = 1e12;
const db eps = 1e-;
const int maxn = 5e3 + ;
const int maxm = 1e5 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) last = ch, ch = getchar();
while(isdigit(ch)) ans = (ans << ) + (ans << ) + ch - '', ch = getchar();
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n, m, a[maxn], c[maxm];
ll dp[maxn]; int main()
{
n = read(); m = read();
for(int i = ; i <= n; ++i) a[i] = read();
sort(a + , a + n + );
for(int i = ; i <= m; ++i) c[i] = read();
for(int i = m - ; i; --i) c[i] = min(c[i], c[i + ]);
for(int i = ; i <= n; ++i) dp[i] = INF;
for(int i = ; i <= n; ++i)
for(int j = ; j <= i; ++j)
dp[i] = min(dp[i], dp[j - ] + c[a[i] - a[j] + ]);
write(dp[n]), enter;
return ;
}

[USACO11DEC]Umbrellas for Cows的更多相关文章

  1. [LeetCode] Bulls and Cows 公母牛游戏

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  2. POJ 2186 Popular Cows(Targin缩点)

    传送门 Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31808   Accepted: 1292 ...

  3. POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)

    传送门 Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 46727   Acce ...

  4. LeetCode 299 Bulls and Cows

    Problem: You are playing the following Bulls and Cows game with your friend: You write down a number ...

  5. [Leetcode] Bulls and Cows

    You are playing the following Bulls and Cows game with your friend: You write a 4-digit secret numbe ...

  6. 【BZOJ3314】 [Usaco2013 Nov]Crowded Cows 单调队列

    第一次写单调队列太垃圾... 左右各扫一遍即可. #include <iostream> #include <cstdio> #include <cstring> ...

  7. POJ2186 Popular Cows [强连通分量|缩点]

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31241   Accepted: 12691 De ...

  8. Poj2186Popular Cows

    Popular Cows Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 31533   Accepted: 12817 De ...

  9. [poj2182] Lost Cows (线段树)

    线段树 Description N (2 <= N <= 8,000) cows have unique brands in the range 1..N. In a spectacula ...

随机推荐

  1. C#项目””是针对”.NETFramework,Version=v4.5.2”但此计算机没有,需要修改为v4.5.1.

    每次下载别人的代码都会出现这样的问题,以为是没有安装.NETFramework,就下载安装了,但是每次安装都会出现已安装高版本的4.6(Win10自带),无需下次安装,但是每次VS中都会显示有问题,而 ...

  2. Maven运行时找不到xml文件和properties文件的问题解决

    使用Maven构建的项目,包下面的xml文件和properties属性文件默认在运行tomcat插件是不会生成文件到target里面的,需要自己配置 一.第一种解决方法也是最常用的解决方法 在pom. ...

  3. 读EntityFramework.DynamicFilters源码_心得_单元测试03

    上个星期我们只是显示了一个示例,怎么在EF的框架内,注入我们拓展的动态过滤器 第一步:安装EntityFramework.DynamicFilters 第二步:重写OnModelCreating方法 ...

  4. CAP理论-解析

          分布式系统的CAP理论:理论首先把分布式系统中的三个特性进行了如下归纳:● 一致性(C):在分布式系统中的所有数据备份,在同一时刻是否同样的值.(等同于所有节点访问同一份最新的数据副本) ...

  5. vim lua对齐indent无效

    查了半天,打开命令 :filetype一看是关闭的 filetype detection:ON  plugin:ON  indent:OFF 在vimrc里打开 filetype indent on ...

  6. ajax接收flask传递的json数据

    from flask import Flask, request import json app = Flask(__name__) @app.route('/') def func(): res = ...

  7. JavaScript AMD 与CMD的代码区别

    1:CMD 依赖就近 define(function(require,export) { var b =1; var a = require("../a"); a.dosometh ...

  8. Sql-exec

    --显示sql server现有的所有数据库 exec sp_helpdb --查看数据表设置的约束 exec sp_helpconstraint SubjectType --update selec ...

  9. ArcSDE 10.2 for Oracle 12C安装注意事项

    ArcSDE 10.2 for Oracle 12C安装注意事项 1.环境说明 从ArcSDE10.2.1开始支持Oracle 12C. 2.安装注意事项 SDE空间数据库可以安装到PDB中,使用Cr ...

  10. 解决Non-resolvable parent POM: Could not find artifact 出现的问题

    在编译spring boot 多模块项目的时候,往往出现 Non-resolvable parent POM: Could not find artifact 后面跟一串其它信息,网上大部分解决方案是 ...