HDU 1085 Holding Bin-Laden Captive! (Primary function)

Source: Internet
Author: User

HDU 1085 Holding Bin-Laden Captive! (Primary function)

Question address

Question:
Here is a cnt1 one-dollar coin, cnt2 two-Yuan coin, and cnt3 five-Yuan coin.

Analysis:
Primary function, formula:
(1 + x ^ 2 + x ^ 3 + ...... x ^ cnt1 )? (1 + x ^ 2 + x ^ 4 + x ^ 6 +... x ^ cnt2 )? (1 + x ^ 5 + x ^ 10 + x ^ 15 +... x ^ cnt5)
Directly simulate it.

Code:

/** Author: illuz
 
  
* File: 1085. cpp * Create Date: 2014-05-25 11:34:37 * Descripton: Generating Function */# include
  
   
# Include
   
    
Const int N = 1e4; int val [3] = {1, 2, 5}, cnt [3]; int c1 [N], c2 [N], mmax; int main () {while (~ Scanf ("% d", & cnt [0], & cnt [1], & cnt [2]) & (cnt [0] | cnt [1] | cnt [2]) {memset (c1, 0, sizeof (c1); memset (c2, 0, sizeof (c2); mmax = 0; for (int I = 0; I <3; I ++) mmax + = cnt [I] * val [I]; for (int I = 0; I <= cnt [0]; I ++) // process the first coin c1 [I] = 1; for (int I = 1; I <3; I ++) {// for each coin behind 1 (int j = 0; j <= mmax; j ++) {if (c1 [j]! = 0) {// for the previous item (c1) for (int k = 0; k <= val [I] * cnt [I]; k + = val [I]) {// simulate multiplication with the current formula if (j + k <= mmax) c2 [j + k] + = c1 [j] ;}}// Save the current item in c1 and clear c2memcpy (c1, c2, sizeof (c1 )); memset (c2, 0, sizeof (c2);} int I; for (I = 0; I <= mmax; I ++) {if (c1 [I] = 0) break;} printf ("% d \ n", I);} 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.