zoukankan      html  css  js  c++  java
  • 采药 ,简单背包 ,代码写得比较差

    #include <stdio.h>
    #include <algorithm>
    #include <memory.h>
    using namespace std;
    int result[1001][101];
    int w[101],v[101];
    int main()
    {
    	int totalTime , count;
    	memset(result , 0 ,sizeof(result));
    	scanf("%d %d" , &totalTime , &count);
    	for ( int i = 1 ;i <= count ; i++)
    		scanf("%d %d" , &w[i] , &v[i]);
    	for ( int i = 1 ; i <= totalTime ; i++)
    		for (int j = 1 ; j <= count ; j++)
    		{
    			if ( i - w[j] >= 0 )
    				result[i][j] = max(result[i][j-1] , result[ i - w[j]][j-1]+v[j])  ;
    			else
    				result[i][j] = result[ i ][ j -1];
    		}
    	printf("%d\n" ,result[totalTime][count]);
    	return 0 ;
    }
    

      

  • 相关阅读:
    Django进阶2
    Django进阶
    Django基础
    jQuery基本操作
    Dom编程
    JavaScript简介
    Python—sqlalchemy
    Python—RabbitMQ
    Python—redis
    Python—操作redis
  • 原文地址:https://www.cnblogs.com/lzhenf/p/2407226.html
Copyright © 2011-2022 走看看