Poj 1164 Apple

Source: Internet
Author: User

Http://poj.org/problem? Id = 1664

This question can be done recursively. I want to put the apple in the first dish from (0 to m) and then to the second one, to ensure that each production method is different, the apple placed in the second one cannot start from 0. Otherwise, the same method will be generated, and the third and fourth plates .... Another problem is that there may be a lot of apples on the last plate. What should I do ?? All put in the last one ?? In fact, this is not the case. It may start with the previous situation. Therefore, you must ensure that this situation cannot be generated during the placement process. (y/(n-x)> = I) this line of code ensures that, because the number of apples in the plate is not decreasing, the number of I remaining dishes, as long as the number of remaining apples divided by the number of remaining dishes is not less than the number of apples on the current plate, we can ensure that this meets the requirements.

// 2013-06-27-14.39 # include <stdio. h> # include <string. h> int n, m, ans; int num [11]; void DFS (int x, int y) {If (x = N) {If (Y> = num [n-1]) ans ++;} else {for (INT I = num [x-1]; I <= Y & (y/(n-x)> = I); I ++) {num [x] = I; DFS (x + 1, y-I) ;}}int main () {int t; scanf ("% d", & T); While (t --) {memset (Num, 0, sizeof (Num); scanf ("% d", & M, & N); ans = 0; DFS (1, M ); printf ("% d \ n", ANS);} return 0 ;}

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.