HDU 2660 accepted neck1_dfs | multiple backpacks

Source: Internet
Author: User

This is a multi-backpack question ..... but there won't be more... it will only be simple... use DFS here ..... however, if you do not pass the current position down, it will time out... I started to get started with TLE and then passed the current status to.

15 ms

#include 
  
    int V [25], W [25]; int des [25], n, k, we, Max, DP [25] [25]; int INF = 0x7fffffff; void DFS (int p, int num, int Val, int Wei) // P is indispensable, otherwise timeout .... tragedy .... {// in the future, you must first consider whether to pass the current status .. to reduce the deep search time, if (num = k | Wei = We) if (Val> MAX) max = val; For (INT I = P; I <= N; ++ I) {If (! Des [I]) if (Num + 1 <= k) & (Wei + W [I] <= We) {des [I] = 1; DFS (I + 1, num + 1, Val + V [I], Wei + W [I]); des [I] = 0 ;}} int main () {int t; scanf ("% d", & T); While (t --) {max = 0; scanf ("% d", & N, & K); For (INT I = 1; I <= N; ++ I) des [I] = 0, scanf ("% d ", & V [I], & W [I]); scanf ("% d", & we); DFS (0, 0, 0, 0); printf ("% d \ n ", max);} return 0;}/* 5 18 31 1 */
  

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.