Test instructions: Give you some boards up to 2 wide and let you put them in a box with a width of two and ask you how long the box is.
Problem solving: DP, the nearest value from the middle.
Problem Solving Code:
1 //File name:a.cpp2 //Author:darkdream3 //Created time:2015 March 28 Saturday 12:13 56 seconds4 5#include <vector>6#include <list>7#include <map>8#include <Set>9#include <deque>Ten#include <stack> One#include <bitset> A#include <algorithm> -#include <functional> -#include <numeric> the#include <utility> -#include <sstream> -#include <iostream> -#include <iomanip> +#include <cstdio> -#include <cmath> +#include <cstdlib> A#include <cstring> at#include <ctime> - #defineLL Long Long - - using namespacestd; - intT; - intN; in intsum; - intdp[10005]; to intMain () { +scanf"%d",&t); - while(t--) the { *sum =0 ; $ inttt =0 ;Panax Notoginsengscanf"%d",&n); - intTA, TB; theMemset (DP,0,sizeof(DP)); +dp[0] =1; A intTsum =0 ; the for(inti =1; I <= N; i + +) + { -scanf"%d%d",&ta,&TB); $ $ if(Ta = =2 ) -Sum + =TB; - Else{ theTsum + =TB; - for(inti = Tsum;i >=0; I-- )Wuyi { the if(Dp[i]! =0 ) - { WuDP[I+TB] =1; - } About } $ } - } - //rintf ("***%d%d\n", sum,tsum); - for(inti = tsum/2; I >=0; I--) A { + if(Dp[i]! =0 ) the { -Sum + = max (i,tsum-i); $ Break; the } the } theprintf"%d\n", sum); the - } in return 0; the}
View Code
Hunan Multi-School Tournament (2015.03.28) arectangle