Bzoj 1571: [usaco 2009 Open] ski course ski

Source: Internet
Author: User
Description

Farmer John wants to ski with Bessie in Colorado. Unfortunately, Bessie's skiing technology is not superb. Bessie understands that S (0 <= S <= 100) Skiing Courses are offered every day at the ski resort. Lesson I starts with m_ I (1 <= m_ I <= 10000), and the last time is L_ I (1 <= L_ I <= 10000 ). After completing section I, Bessie's skiing capacity will change to a_ I (1 <= a_ I <= 100). Note: This capacity is absolute, not a growth value. Bessie bought a map showing N (1 <= n <= 10,000) slopes for skiing, duration d_ I (1 <= d_ I <= 10000) required to slide from the top of slope I to the bottom ), and the skiing capacity C_ I (1 <= C_ I <= 100) required for each slope to ensure the safety of skiing. Bessie's ability must be greater than or equal to this level so that she can slide securely. Bessie can spend her time skiing, attending classes, or drinking a cup of cocoa, but she must leave the ski resort at T (1 <= T <= 10000. This means that she had to complete the last skiing before t moment. Find the maximum number of skiing times that Bessie can complete in the implementation. At the beginning of the day, her skiing capacity was 1. Input

Row 3: Three integers separated by spaces: T, S, N.

2nd ~ Row S + 1: The ski class I + 1 is described by an integer separated by three spaces: m_ I, L_ I, a_ I.

S + 2 ~ S + n + 1 row:

Line S + I + 1 uses an integer separated by two spaces to describe the I slice: C_ I, d_ I. Output

An integer that indicates the maximum number of skiing times that Bessie can complete within the time limit.

Question:

For dynamic planning, F [I] [J] indicates the maximum number of skiing times with the capability value J During I time.

Corresponding to the last three options:

① Delicious drink a cup of cocoa juice f [I] [J] = f [I-1] [J],

② Class F [I] [J] = f [one time before class] [arbitrary],

③ Skiing f [I] [J] = f [I-po [J] [J] + 1 (po [J] is a one-time skiing event with a capacity value <= J shortest time ).

For ② the last start time of the course where ke [I] [J] can end at the I moment and the capability value reaches J. In the DP process, G [I] = max {f [I] [J]} is processed.

G [T] is the answer.

Code:

#include<cstdio>#include<cstring>#include<algorithm>//by zrt//problem:using namespace std;int f[10005][105];int t,s,n;int ke[10005][105];int po[105];int g[10005];int main(){    #ifdef LOCAL    freopen("in.txt","r",stdin);    freopen("out.txt","w",stdout);    #endif    memset(f,128,sizeof f);    scanf("%d%d%d",&t,&s,&n);    for(int i=1,m,l,a;i<=s;i++){        scanf("%d%d%d",&m,&l,&a);        ke[m+l-1][a]=max(ke[m+l-1][a],m);    }    memset(po,0x3f,sizeof po);    for(int i=1,c,d;i<=n;i++){        scanf("%d%d",&c,&d);        for(int j=c;j<=100;j++){            po[j]=min(po[j],d);        }    }    f[0][1]=0;    g[0]=0;    for(int i=1;i<=t;i++){        for(int j=1;j<=100;j++){            f[i][j]=f[i-1][j];            if(ke[i-1][j])f[i][j]=max(f[i][j],g[ke[i-1][j]]);            if(i-po[j]>=0)f[i][j]=max(f[i][j],f[i-po[j]][j]+1);            g[i]=max(g[i],f[i][j]);        }    }    printf("%d\n",g[t]);    return 0;}

Bzoj 1571: [usaco 2009 Open] ski course ski

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.