分析:暴力挺好打的,对于前30%的数据神搜,hi相同的数据将所有的建筑按照c从小到大排序,看最多能跳多少,ci=0的数据将所有的建筑按照h从小到大排序,枚举起点和终点,看能否跳这么多,取个max就可以了.这样70分就到手了.

部分分的提示还是比较明显的,要消除一个参数的影响,那么就按照h从小到大排序,显然只有可能顺着跳过城市,不能跳过去又跳回来.那么就是一个比较简单的dp了:f[i][j]表示跳了i次,最后一次跳到j的最小花费,转移的话枚举j之前的k就能转移了,最后倒叙枚举i看哪一个f[i][j]<=T就可以了.

多个参数有影响的常见策略是消除一个参数的影响,常见的办法就是排序,如果一个点不能经过多次,那么就想一个办法让它强行不经过这个点.

暴力:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n, T, ans, vis[];
bool flag1 = true, flag2 = true; struct node
{
int c, h;
}e[]; bool cmp1(node a, node b)
{
return a.c < b.c;
} bool cmp2(node a, node b)
{
return a.h < b.h;
} void dfs(int u, int sum,int tot)
{
ans = max(ans, tot + );
vis[u] = ;
for (int i = ; i <= n; i++)
{
if (!vis[i])
{
int huafei = abs(e[i].h - e[u].h) + e[u].c;
if (sum + huafei <= T)
dfs(i, sum + huafei, tot + );
}
}
} int main()
{
scanf("%d", &n);
for (int i = ; i <= n; i++)
{
scanf("%d", &e[i].c);
if (e[i].c != )
flag2 = false;
}
for (int i = ; i <= n; i++)
{
scanf("%d", &e[i].h);
if (i != && e[i].h != e[i - ].h)
flag1 = false;
}
scanf("%d", &T);
if (n <= || (!flag1 && !flag2))
{
for (int i = ; i <= n; i++)
{
memset(vis, , sizeof(vis));
dfs(i,,);
}
printf("%d\n", ans);
}
else
if (flag1)
{
sort(e + , e + + n, cmp1);
int res = , cur = ;
while (cur <= n && res <= T)
{
ans++;
res += e[cur].c;
cur++;
}
printf("%d\n", ans - );
}
else
{
sort(e + , e + + n, cmp2);
for (int i = ; i <= n; i++)
{
int j = i + , res = ;
while (j <= n && res <= T)
{
res += abs(e[j].h - e[j-].h);
j++;
}
ans = max(ans, j - i + );
}
printf("%d\n", ans - );
} return ;
}

正解:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n,T;
int f[][]; struct node
{
int c, h;
}e[]; bool cmp(node a, node b)
{
return a.h < b.h;
} int main()
{
memset(f, / , sizeof(f));
scanf("%d", &n);
for (int i = ; i <= n; i++)
scanf("%d", &e[i].c);
for (int i = ; i <= n; i++)
scanf("%d", &e[i].h);
scanf("%d", &T);
sort(e + , e + + n, cmp);
f[][] = e[].c;
for (int i = ; i <= n; i++)
for (int j = ; j <= n; j++)
for (int k = j + ; k <= n; k++)
f[i + ][k] = min(f[i + ][k], f[i][j] + e[k].h - e[j].h + e[k].c); for (int i = n; i >= ; i--)
for (int j = ; j <= n; j++)
if (f[i][j] <= T)
{
printf("%d\n", i + );
return ;
}
printf("0\n"); return ;
}

noip模拟赛 遭遇的更多相关文章

  1. NOIP模拟赛20161022

    NOIP模拟赛2016-10-22 题目名 东风谷早苗 西行寺幽幽子 琪露诺 上白泽慧音 源文件 robot.cpp/c/pas spring.cpp/c/pas iceroad.cpp/c/pas ...

  2. contesthunter暑假NOIP模拟赛第一场题解

    contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...

  3. NOIP模拟赛 by hzwer

    2015年10月04日NOIP模拟赛 by hzwer    (这是小奇=> 小奇挖矿2(mining) [题目背景] 小奇飞船的钻头开启了无限耐久+精准采集模式!这次它要将原矿运到泛光之源的矿 ...

  4. 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程

    数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...

  5. 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...

  6. 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...

  7. 队爷的新书 CH Round #59 - OrzCC杯NOIP模拟赛day1

    题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的新书 题解:看到这题就想到了 poetize 的封 ...

  8. CH Round #58 - OrzCC杯noip模拟赛day2

    A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...

  9. CH Round #52 - Thinking Bear #1 (NOIP模拟赛)

    A.拆地毯 题目:http://www.contesthunter.org/contest/CH%20Round%20%2352%20-%20Thinking%20Bear%20%231%20(NOI ...

随机推荐

  1. P4110 [HEOI2015]小L的白日梦

    传送门 题解 //minamoto #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef l ...

  2. vs2017 + miniUI + dapper 添加、修改、删除、查询操作

    A.数据库表引用先前建立的company 公司信息表. B.建立文件: views > Home > Company.cshtml(新建文件) ,代码如下(直接复制即可) @{ Layou ...

  3. sqlalchemy配置多读写库多连接后的关系设置

    前言 一般来说,解决sqlalchemy 连接多个库的最简单的方式是新建两个或多个db.session 相互没有关联,modle配置不同的db.session来连接,这样的话,relationship ...

  4. python re的使用

    re 正则表达式操作  本模块提供了类似于Perl的正则表达式匹配操作.要匹配的模式和字符串可以是Unicode字符串以及8位字符串. 正则表达式使用反斜杠字符('\')来表示特殊的形式或者来允许使用 ...

  5. 洛谷P1010 幂次方

    题目描述 任何一个正整数都可以用2的幂次方表示.例如 137=2^7+2^3+2^0 同时约定方次用括号来表示,即a^b 可表示为a(b). 由此可知,137137可表示为: 2(7)+2(3)+2( ...

  6. DP Codeforces Round #FF (Div. 1) A. DZY Loves Sequences

    题目传送门 /* DP:先用l,r数组记录前缀后缀上升长度,最大值会在三种情况中产生: 1. a[i-1] + 1 < a[i+1],可以改a[i],那么值为l[i-1] + r[i+1] + ...

  7. 295 Find Median from Data Stream 数据流的中位数

    中位数是排序后列表的中间值.如果列表的大小是偶数,则没有中间值,此时中位数是中间两个数的平均值.示例:[2,3,4] , 中位数是 3[2,3], 中位数是 (2 + 3) / 2 = 2.5设计一个 ...

  8. Mac上简单常用Terminal命令

    方案1 SSH是一个非常伟大的工具,如果你要在互联网上远程连接到服务器,那么SSH无疑是最佳的候选.SSH是加密的,OpenSSH加密所有通信(包括密码),有效消除了窃听,连接劫持和其它攻击.本文将为 ...

  9. STL_map的使用

    转自:http://www.kuqin.com/cpluspluslib/20071231/3265.html Map是STL的一个关联容器,它提供一对一(其中第一个可以称为关键字,每个关键字只能在m ...

  10. ThinkPHP---thinkphp文件加载

    [一]文件加载在ThinkPHP里提供了三种方式 实际开发里,文件加载方式一般以第一种为主(通过函数库形式自动加载,此时我们仅仅需要定义文件和函数) (1)函数库形式加载 函数库分3种级别,系统函数库 ...