I threw the eggs for one night and found out the best place for the first time.

Source: Internet
Author: User

I threw the eggs for one night and found out the best place for the first time.

Http://blog.csdn.net/joylnwang/article/details/6769160

Let's take a look at the problem of throwing eggs. All the principles are implemented by DP. Everyone should study hard and learn every day.

What I want to share is:

Recursive lookup of the best place to be thrown for the first time: (I have passed all my tests. I hope everyone will check the errors. I want to find all the demarcation points according to what the gods mean, that is to say, it is too difficult to find the broken or not broken eggs. When can I share it with you)


Code Description:

# Include <cstdio> # include <string> # include <cmath> # include <algorithm> using namespace std; int steps = 0; const int maxn = 100; const int maxm = 100; int drop [maxn] [maxm]; int Max; int before; int Dropping (int n, int m) // run one-time memory DP, find the optimal value and save the intermediate process {if (n = 1) return drop [n] [m] = m; if (n> = m) return drop [n] [m] = pow (2, m)-1; if (drop [n-1] m-1] = 0) Dropping (N-1 m-1 ); if (drop [n] [M-1] = 0) Dropping (n, s-1); return drop [n] [m] = Dropping (N-1 m-1) + 1 + Dropping (m-1);} int findans (int n, int m) // find the first test point of the current maximum value !! {Int ans; if (n = 1) // process the first case {for (int I = before + 1; I <= Max; I ++) printf ("% d % c", I, I = Max? '\ N': '');} else if (n <m) // process recursive decomposition {ans = Max-drop [n] [s-1]; // use Max to subtract the number of before = ans; // before records the last vertex where printf ("% d", ans); if (Max-ans) // if ans = Max, it indicates that the eggs have been thrown to the top layer {printf (""); findans (m-1);} else printf ("\ n ");} else // process the case when n = m. Every time you look back, the interval is equivalent to two points {if (n> 0) {ans = before + pow (2 m-1 ); // before records where before = ans; printf ("% d", ans); if (Max-ans) {printf (""); findans (N-1 m-1);} else printf ("\ n") ;}} int Main () {int n, m; // n = 2, m = 8; memset (drop, 0, sizeof (drop); scanf ("% d ", & n, & m); printf ("% d \ n", Dropping (n, m); Max = drop [n] [m]; before = 0; findans (n, m); return 0;}/* In fact, this is only an example of D [n, m]. In fact, this first case of throwing an egg applies completely: all the reasons for D [M-1] <k <= D [n, m]: It's nothing more than compressing the following complete intervals! */


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.