Test instructions: give you n book, you can put it upright, and then can also be placed sideways on the vertical book, but not beyond the vertical edge of the display, and can not be stacked. Ask you what the minimum width is in the upright position.
Problem-solving ideas: Dp,dp[i][j] Represents the first I, with the vertical placement of the book of J horizontal positioning of the minimum value
Problem Solving Code:
1 /************************************************************2 * Author:darkdream3 * Email: [Email protected]4 * Last modified:2015-03-09 20:325 * Filename:294b.cpp6 * Description:7 * *********************************************************/8 //File name:294b.cpp9 //Author:darkdreamTen //Created time:2015 March 09 Monday 20:04 53 Seconds One A#include <vector> -#include <list> -#include <map> the#include <Set> -#include <deque> -#include <stack> -#include <bitset> +#include <algorithm> -#include <functional> +#include <numeric> A#include <utility> at#include <sstream> -#include <iostream> -#include <iomanip> -#include <cstdio> -#include <cmath> -#include <cstdlib> in#include <cstring> -#include <ctime> to #defineLL Long Long + - using namespacestd; the structnode{ * intT, W; $}a[ $];Panax Notoginseng intdp[ $][ -]; - intMain () { the intN; +scanf"%d",&n); Amemset (dp,-1,sizeof(DP)); the intTotal =0 ; + for(inti =1; I <= N;i + +) - { $scanf"%d%d",&a[i].t,&A[I].W); $Total + =a[i].t; - } -dp[0][0] =0 ; the intMi =1e9; - for(inti =1; I <= N;i + +)Wuyi { the for(intj =0; J <= Total;j + +) - { WuDP[I][J] = dp[i-1][j]; - } About for(intj =0; J <= Total;j + +) $ { - if(dp[i-1][J]! =-1) - { - if(dp[i-1][J+A[I].T] = =-1) ADP[I][J+A[I].T] = dp[i-1][J] +A[I].W; + ElseDP[I][J+A[I].T] = min (dp[i][j+a[i].t],dp[i-1][J] +A[I].W); the } - } $ } the for(inti =1; I <= N;i + +) the { the for(intj=0; J <= Total; j + +) the { - //printf ("%d", dp[i][j]); in if(Dp[i][j] <= total-j && dp[i][j]! =-1) themi = min (mi,total-j); the } About //printf ("\ n"); the the } theprintf"%d\n", MI); + return 0; -}
View Code
Codeforces 294B Shaass and Bookshelf