TYVJ p2018"nescafé26" Kitten Mountain climbing Problem Solving report

Source: Internet
Author: User
Tags define local

P2018 "nescafé26" Kitten Climbing

Time: 1000ms/Space: 131072kib/java class name: main background

Freda and Rainbow raised n kittens, and on this day, the kittens were going to climb mountains. After a long journey, the kittens climbed to the top of the mountain, but they did not want to walk down the hill again (Woo Goo >_<).

Describe

Freda and Rainbow had to pay for them to take the ropeway down the mountain. The cable car on the ropeway has a maximum bearing weight of W, while the weight of n kittens is C1, C2 ... CN. Of course, the weight of the kitten on each cable car cannot exceed W. Freda and Rainbow pay $1 for every cable car they hire, so they want to know at least how many dollars they need to pay to get the N kittens down the hill?

Input format

The first line contains two integers separated by a space, N and W.
The next n lines are an integer per line, where the integer of line i+1 represents the weight ci of the I kitten.

Output format

Output an integer that requires at least the minimum number of dollars, which is the minimum number of cable cars required.

Test Sample 1 input
5 1996
1
2
1994
12
in
Output
2
Note

For 100% of data, 1<=n<=18,1<=ci<=w<=10^8.
Nescafé26

—————————————————————— I'm a split line —————————————————————————————

Id-dfs topic.

? Enumerate the answers from 1~n, and iterate to deepen the search.? Each time the DFS is enumerated, enumerate each kitten on which cable car is placed.  This will be tle, so let's add a pruning:? * The I kitten can only be placed on the front I cable car (no meaning on the back of the car).   This at first glance does not understand, another look but found-this is not the drawer principle??? qaq~ This is AC, the core code is not long.
1 /*2 PROBLEM:TYVJ 20183 OJ:TYVJ4 USER:S.B.S.5 time:169 Ms6 memory:1316 KB7 length:n/a8 */9#include <iostream>Ten#include <cstdio> One#include <cstring> A#include <cmath> -#include <algorithm> -#include <queue> the#include <cstdlib> -#include <iomanip> -#include <cassert> -#include <climits> +#include <functional> -#include <bitset> +#include <vector> A#include <list> at#include <map> - #defineMAXN 100001 - #defineF (i,j,k) for (int i=j;i<=k;i++) - #defineM (A, B) memset (A,b,sizeof (a)) - #defineFF (i,j,k) for (int i=j;i>=k;i--) - #defineINF 0x3f3f3f3f in #defineMAXM 1001 - #defineMoD 998244353 to //#define LOCAL + using namespacestd; - intRead () { the     intx=0, f=1;CharCh=GetChar (); *      while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} $      while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();}Panax Notoginseng     returnx*F; - } the intn,m,w; + intdep,ans=-1; A intC[MAXN],RE[MAXN]; theInlinevoidDfsintu) + { -     intb;BOOLflag=false; $     if(ans!=-1)return; $     if(u>N) { -ans=DEP; -         return; the     } -F (I,1, Min (U,DEP)) {Wuyi         if(W-re[i]<c[u])Continue; there[i]+=c[u];flag=true; -DFS (u+1); Wu         if(ans!=-1)return; -re[i]-=C[u]; About     } $     if(flag==false)return; - } - intMain () - { AStd::ios::sync_with_stdio (false); + #ifdef LOCAL theFreopen ("data.in","R", stdin); -Freopen ("Data.out","W", stdout); $     #endif theCin>>n>>W; theF (I,1, N) cin>>C[i]; the      for(dep=1;; dep++){ theDfs1); -         if(ans!=-1){ incout<<ans<<Endl; the              Break; the         } About     } the     return 0; the}
View Code

TYVJ p2018"nescafé26" Kitten Mountain climbing Problem Solving report

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.