HDU 1028 Ignatius and the Princess III (integer division)

Source: Internet
Author: User
Tags integer division

Topic links

Dynamic programming recursion for classical DP integer partitioning problem

Set DP[I][J] = Split fraction I, the largest so the number does not exceed the number of J scheme.

The first is that the last number does not exceed j-1, at which point the number of scenarios is dp[i][j-1], or the last number is just J, at which point the number of scenarios is dp[i-j][j].

Pay attention to some boundary conditions.

1#include <iostream>2#include <cstring>3#include <cstdio>4#include <string>5#include <algorithm>6 using namespacestd;7 #defineMAXN 1308 intdp[ the][ the];9 voidinit () {TenMemset (DP,0,sizeof(DP)); One      for(inti =0; I <= the; i++){ Adp[0][i] =1;//0 -dp[i][1] =1;//are split into 1 -dp[1][i] =1;  the     } -      for(inti =2; I <= the; i++){ -          for(intj =2; J <= the; J + +){ -             if(j<=i) Dp[i][j] = dp[i][j-1] + dp[i-J] [j]; +             ElseDP[I][J] =Dp[i][i]; -         } +     } A } at intMain () { -     intN; - init (); -      while(SCANF ("%d", &n)! =EOF) { -cout<<dp[n][n]<<Endl; -     } in     return 0; -}

HDU 1028 Ignatius and the Princess III (integer division)

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.