Codeforces 294B Shaass and Bookshelf

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.