joj2256

 2256: Frog & Bridge

Result TIME Limit MEMORY Limit Run Times AC Times JUDGE
10s 32768K 1070 170 Standard
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;
}

你可能感兴趣的:(joj2256)