Bzoj 1571: [Usaco2009 Open] Skiing ski class

Source: Internet
Author: User

Description

Farmer John wants to go skiing with Bessie together in Colorado State. Unfortunately, Bessie Ski technology is not superb. Bessie learned that S (0<=s<=100) ski lessons are offered daily at the ski slopes. Section I starts at M_i (1<=m_i<=10000) and is L_i (1<=l_i<=10000). After Class I, Bessie's ability to ski will become a_i (1<=a_i<=100). Note: This ability is absolute, not the ability to increase the value. Bessie bought a map showing N (1 <= n <= 10,000) slopes available for skiing, sliding from the top of the first slope to the length of time d_i (1<=d_i<=10000) required for the bottom, and the ski capacity required for each ramp c_i ( 1<=C_I<=100) to ensure the safety of the ski. The ability of the Bessie must be greater than or equal to this level so that she can safely slide down. Bessie can use her time to ski, class, or have a nice cup of cocoa, but she has to leave the ski slopes at T (1<=t<=10000). This means she has to finish the last ski before the T-moment. Ask Bessie how many skis can be completed within the implementation. At the beginning of the day, her skiing capacity was 1.

Input

Line 1th: 3 integers separated by a space: T, S, N.

Line 2~s+1: Line i+1 uses 3 spaces separated by an integer to describe the ski lesson numbered I: m_i,l_i,a_i.

Line s+2~s+n+1:

Line S+i+1 uses a 2-space-separated integer to describe the I ski slope: c_i,d_i.

Output

An integer that indicates how many skis Bessie can complete within the time limit.

Sample Input10 1 2
3 2 5
4 1
1 3

Sample Output6
HINT

Slide the second ski slope 1 times, then class, then slide 5 times on the first ski slope.

Problem Solving Report:
It's easy to design the state, dp[i][j] means I have the maximum capacity J at the moment, then there are three kinds of transfer
1. Not doing anything
2. Study Course
3. Skiing
And then we'll use a memory search.

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 #defineMAXN 200006 using namespacestd;7 structT8 {9     intx;Ten     inty; One     intZ; A }A[MAXN]; - intdp[maxn][ $], W[MAXN], t,s,n; - intDfsintXinty) the { -     if(x==5&& y = =5) -     { -         intU =1; +     } -     if(x > t)return-0x3f3f3f3f; +     if(x = = t)return 0; A     if(Dp[x][y]! =-1)returnDp[x][y]; at     int&ret = Dp[x][y] =0; -      for(inti =1; I <= s;i++) -     { -         if(A[i].x < X)Continue; -RET = max (ret, DFS (a[i].x +a[i].y,a[i].z)); -     } inRET = max (ret, DFS (x +1, y)); -RET = max (ret, DFS (x + w[y], y) +1); to     returnret; + } -  the intMain () * { $     intx, y;Panax Notoginsengscanf"%d%d%d",&t,&s,&n); -      for(intI=1; i<=s;i++) the     { +scanf"%d%d%d",&a[i].x,&a[i].y,&a[i].z); A     } thememset (dp,-1,sizeof(DP)); +Memset (W,0x3f,sizeof(w)); -      for(intI=1; i<=n;i++) $     { $scanf"%d%d",&x,&y); -W[X] =min (w[x],y); -     } the      for(intI=1; i<= -; i++) -     {WuyiW[i] = min (w[i],w[i-1]); the     } -     intAns = DFS (0,1); Wuprintf"%d\n", ans); -     return 0; About}

Bzoj 1571: [Usaco2009 Open] Skiing ski class

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.