zoukankan      html  css  js  c++  java
  • (RQoj 15采药------rwkj 10.1.5.253 1447) 记忆式搜索 1

    #include <iostream>
    using namespace std;
    int dp[105][1005],w[105],v[105] ;

    int max(int a,int b) { return a > b ? a : b; }
    int f(int x,int y)
    { int t ;
    if(dp[x][y]!=-1) return dp[x][y] ;
    if(x==0 || y==0 ) return dp[x][y]=0 ;
    else
    {
    t=f(x-1,y) ;                                                                                  //前x-1    算出来,,,保留在  t 中,,,,保留以前计算过
    if(y>=w[x])        dp[x][y]=max(t,   f(x-1,  y-w[x]   ) +v[x] );     //  装得下 ,,,,,装上------不装   第x种

         else               dp[x][y]=t;                                                       //否则,,装不下,,               不装   第x种
    }
    return dp[x][y];

    }

    int main()
    {
    int T,M,i,j ;
    cin>>T>>M ;
    for(i=1;i<=M ;i++) cin>>w[i]>>v[i];
    memset(dp ,-1,sizeof(dp));
    f(M,T) ;
    cout<<dp[M][T]<<endl;

    }

    **************************************************************************************


    hnldyhy(303882171) 9:32:14
    #include <iostream>
    #include <string.h>
    using namespace std;
    int dp[105][1005], w[105],v[105],T,M;
    int max(int x,int y) { return x>y?x:y; }
    int f(int x,int y)
    { int t;
    if (dp[x][y]!=-1) return dp[x][y];
    if ( x==0 || y==0 ) return dp[x][y]=0;
    else
    { t=f(x-1,y);
    if ( y>=w[x] ) dp[x][y]=max(t,f(x-1,y-w[x])+v[x] ); else dp[x][y]=t;
    }
    return dp[x][y] ;
    }
    int main()
    { int T,M,i,j;
    cin>>T>>M;
    for ( i=1; i<=M; i++) cin>>w[i]>>v[i];
    memset(dp,-1,sizeof(dp));
    f(M,T);
    cout<<dp[M][T]<<endl;
    return 0;
    }

  • 相关阅读:
    AX7 VM can not starting
    AX3空Invoice明细问题
    Solution to “VirtualBox can't operate in VMX root mode” error in Windows 7
    Inventory of the materials to teach you how to query a date certain combination of dimensions
    How to Debug Enterprise Portal Code in Dynamics AX 2009
    Axapta 3 COM Connector
    AX 与Citrix打印机问题
    AX ERP 真正的自动批处理
    SQL语句转摘
    D365: Table, Form, Class to extension
  • 原文地址:https://www.cnblogs.com/2014acm/p/3908346.html
Copyright © 2011-2022 走看看