Codeforces339c-Xenia and weights Brute Force Search

Source: Internet
Author: User

Question: I will give you an infinite number of 1-10 records, from 1-M to the two ends of the balance, and place them on different balances and different weights for two consecutive times, this means that the balances placed here each time are much heavier than those placed on the opposite side.

Solution:

1) brute-force search, if estimated, still cannot pass, but the actual situation is much better than the estimated 62 Ms

 
1 // file name: 339c. CPP 2 // Author: darkdream 3 // created time: sunday, November 16, August 03, 2014 4 5 # include <vector> 6 # include <list> 7 # include <map> 8 # include <set> 9 # include <deque> 10 # include <stack> 11 # include <bitset> 12 # include <algorithm> 13 # include <functional> 14 # include <numeric> 15 # include <utility> 16 # include <sstream> 17 # include <iostream> 18 # include <iomanip> 19 # include <cstdio> 20 # include <cmath> 2 1 # include <cstdlib> 22 # include <cstring> 23 # include <ctime> 24 # define ll long long25 26 using namespace STD; 27 int ans [1004]; 28 int num = 0; 29 int B [30]; 30 int lB = 0; 31 int m; 32 int DFS (INT num, int last, int K) 33 {34 if (k = m + 1) 35 return 1; 36 for (INT I = 1; I <= LB; I ++) 37 {38 If (B [I]> num & B [I]! = Last) 39 {40 if (DFS (B [I]-num, B [I], k + 1) 41 {42 ans [k] = B [I]; 43 return 1; 44} 45} 46} 47 return 0; 48} 49 int main () {50 char STR [14]; 51 scanf ("% s", STR ); 52 scanf ("% d", & M); 53 int Len = strlen (STR); 54 for (INT I = 0; I <Len; I ++) 55 {56 If (STR [I] = '1') 57 {58 LB ++; 59 B [LB] = I + 1; 60} 61} 62 if (DFS (0, 0, 1) 63 {64 printf ("Yes \ n"); 65 for (INT I = 1; I <= m; I ++) 66 printf ("% d", ANS [I]); 67} else {68 printf ("NO \ n"); 69} 70 return 0; 71}
View code

2) DP

DP [I] [J] [k] is basically similar to brute-force search. However, when repeated records are removed, the code will be written back after dinner and Qaq will be written.

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.