joj2256

 2256: Frog & Bridge


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
10s32768K1070170Standard
A frog is going to jump across a bridge, where there are stones. The frog is considering how he can step on the stones as few times as possible. Can you help him?

The bridge is composed by a series of unit positions ranging from 0 to L, and the frog wants to jump from 0 and to or over L. Each time the frog is able to jump S unit positions at least and T unit positions at most.

INPUT

An integer N in the first line of the input file indicates the number of test cases to be done. Then from the second line, there are exactly N test cases. The first line of each test case consists of an integer L. In the second line, there are three integers S, T, M. There are exactly M integers in the third line, indicating the positions where the stones are placed.

It is guaranteed that L is less than (or equal to) 1000, and M is less than (or equal to) 100, and S, T no longer exceed 10.

OUTPUT

For each test case, print the minimal number of stones the frog has to step on in order to jump across the bridge in a single line.

SAMPLE INPUT

1
10
2 3 5
2 3 5 6 7

SAMPLE OUTPUT

2
Note:
A solution for this case is 0 3 6 8 10
Therefore, 3 and 6 are the two stones.

Problem Source: 4th JLU Programming Contest


This problem is used for contest: 39 


Submit / Problem List / Status / Discuss





 

这是一个让我非常蛋疼纠结的问题。首先在找递推关系式的时候出现了错误,再就是在编码的时候,弄错了一个地方,见标注





#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int dp[2000+10];
int main()
{
    freopen("in.txt","r",stdin);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        int l;
        cin>>l;
        int s,t,m;
        cin>>s>>t>>m;
        memset(dp,0,sizeof(dp));
        for(int j=1;j<=m;j++)
        {
            int u;
            cin>>u;
            dp[u]=1;
        }
        for(int j=1;j<l+t;j++)
        {
            int mmin=1000000;
            for(int k=j-t;k<=j-s;k++)
            {
                if(k<0)continue;//这句话必须有,否则就会造成这个循环的某些环节没有执行。。。。
                if(mmin>dp[k])mmin=dp[k];
            }
            dp[j]+=mmin;
        }
        int mmin=10000000;
        for(int j=l;j<l+t;j++)
        {
            if(mmin>dp[j])mmin=dp[j];
        }
        cout<<mmin<<endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值