luogu4265 [USACO18FEB]Snow Boots S

http://www.elijahqi.win/2018/03/06/luogu4265-usaco18febsnow-boots-s/
题目描述

It’s winter on the farm, and that means snow! There are NN tiles on the path from the farmhouse to the barn, conveniently numbered 1 \dots N1…N , and tile ii is covered in f_ifi​ feet of snow. Farmer John starts off on tile 11 and must reach tile NN to wake up the cows. Tile 11 is sheltered by the farmhouse roof, and tile NN is sheltered by the barn roof, so neither of these tiles has any snow. But to step on the other tiles, Farmer John needs to wear boots!

In his foul-weather backpack, Farmer John has BB pairs of boots, numbered 1 \dots B1…B . Some pairs are more heavy-duty than others, and some pairs are more agile than others. In particular, pair ii lets FJ step in snow at most s_isi​ feet deep, and lets FJ move at most d_idi​ forward in each step.

Unfortunately, the boots are packed in such a way that Farmer John can only access the topmost pair at any given time. So at any time, Farmer John can either put on the topmost pair of boots (discarding his old pair) or discard the topmost pair of boots (making a new pair of boots accessible).

Farmer John can only change boots while standing on a tile. If that tile has ff feet of snow, both the boots he takes off AND the boots he puts on must be able to withstand at least ff feet of snow. Intermediate pairs of boots which he discards without wearing do not need to satisfy this restriction.

Help Farmer John minimize waste, by determining the minimum number of pairs of boots he needs to discard in order to reach the barn. You may assume that Farmer John is initially not wearing any boots.

输入输出格式

输入格式:
The first line contains two space-separated integers NN and BB (2 \leq N,B \leq 2502≤N,B≤250 ). The second line contains NN space-separated integers. The ii th integer is f_ifi​ , giving the depth of snow on tile ii (0 \leq f_i \leq 10^90≤fi​≤109 ). It’s guaranteed that f_1 = f_N = 0f1​=fN​=0 .

The next BB lines contain two space-separated integers each. The first integer on line i+2i+2 is s_isi​ , the maximum depth of snow in which pair ii can step. The second integer on line i+2i+2 is d_idi​ , the maximum step size for pair ii . It’s guaranteed that 0 \leq s_i \leq 10^90≤si​≤109 and 1 \leq d_i \leq N-11≤di​≤N−1 .

The boots are described in top-to-bottom order, so pair 11 is the topmost pair in FJ’s backpack, and so forth.

输出格式:
The output should consist of a single integer, giving the minimum number of boots Farmer John needs to discard. It’s guaranteed that it will be possible for FJ to make it to the barn.

输入输出样例

输入样例#1: 复制
10 4
0 2 8 3 6 7 5 1 4 0
2 3
4 2
3 4
7 1
输出样例#1: 复制
2
说明

Problem credits: Brian Dean and Dhruv Rohatgi

判断用最少的靴子能否从1走到n 直接o(n^3)暴力枚举dp即可

#include<cstdio>
#include<algorithm>
#define ll long long
#define N 300
using namespace std;
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
inline int read(){
    int x=0,f=1;char ch=gc();
    while(ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=gc();}
    while(ch<='9'&&ch>='0') x=x*10+ch-'0',ch=gc();
    return x*f;
}
struct node{
    int s,d;
}b[N];
int n,B,tile[N];
bool visit[N],dp[N][N];
//dp[i][j]表示在第i块地方是否可以使用第j个靴子
int main(){
//  freopen("snowboots.in","r",stdin);
//  freopen("snowboots.out","w",stdout);
    n=read();B=read();
    for (int i=1;i<=n;++i) tile[i]=read();dp[1][0]=1;
    for (int i=1;i<=B;++i) b[i].s=read(),b[i].d=read();
    for (int i=1;i<=n;++i){
        for (int j=1;j<=B;++j) {
            if (b[j].s<tile[i]) continue;
            for (int k=0;k<j;++k) dp[i][j]|=dp[i][k];
        }
        for (int j=1;j<=B;++j){
            if (!dp[i][j]) continue;
            for (int k=1;k<=b[j].d;++k){
                int to=k+i;if (to>n||b[j].s<tile[to]) continue;
                dp[to][j]|=dp[i][j];
            }
        }   
    }int ans;
    for (int i=1;i<=B;++i) if (dp[n][i]) {ans=i-1;break;}
    printf("%d",ans);
    return 0;
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值