zoukankan      html  css  js  c++  java
  • 动态规划 DP

    动态规划 DP
    我们用f[ i ] 表示从 i 点出发到达终点的最多能休息的时间

    然后我们发现 状态转移方程
    f[ i ] = f[ i+1 ] +1 ; 当该点 并没有工作计划时
    f[ i ] = max(f[ i+len ],f[ i ]); 当该点 有工作计划时 一个或若干个

     1 #include <bits/stdc++.h> 
     2 #define For(i,j,k) for(int i=j;i<=k;i++) 
     3 using namespace std ; 
     4 
     5 const int N = 10011 ; 
     6 int n,k,p,len;  
     7 int f[N] ;  
     8 vector <int> v[N] ; 
     9 vector <int> :: iterator it ; 
    10 
    11 inline int read() 
    12 {
    13     int x = 0 , f = 1 ; 
    14     char ch = getchar() ; 
    15     while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; } 
    16     while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; } 
    17     return x * f ; 
    18 }
    19 
    20 int main() 
    21 {
    22     n = read() ; k = read() ; 
    23     For(i,1,k)  {
    24         p = read() ;   len = read() ; 
    25         v[ p ].push_back( len ) ; 
    26     }
    27     f[ n+1 ] = 0 ; 
    28     for(int i=n;i>=1;i--)    {
    29         if( v[ i ].empty() ) 
    30             f[ i ] = f[ i+1 ] + 1 ; 
    31         else 
    32             for(it=v[ i ].begin();it!=v[ i ].end();it++) {
    33                 len = *it ; 
    34                 f[ i ] = max( f[ i ],f[ i+len ] ) ; 
    35              } 
    36     }
    37     printf("%d
    ",f[ 1 ]) ; 
    38     return 0 ; 
    39 }
  • 相关阅读:
    购物车宣传页
    项目开发流程
    AJAX跨域
    jQuery中的AJAX
    AJAX封装
    AJAX里使用模板引擎
    AJAX的具体使用
    AJAX的基本使用
    js技巧汇总
    CSS特效汇集
  • 原文地址:https://www.cnblogs.com/third2333/p/7214335.html
Copyright © 2011-2022 走看看