UV 10313-pay the price

Source: Internet
Author: User

Question: Calculate the repeated split of an integer to limit the number of split scores.

Analysis: DP, two-dimensional multiple backpacks. Use a backpack for integer splitting.

Status: set f (I, j) to split J into I elements;

Transfer: f (I, j) = sum (f (I-1, J-k), F (I-1, j-2k ),..., F (I-1, J-mk) {Where, 1 ≤ k ≤ j };

Because the input format is wa many times, powerful sscanf (⊙ o ⊙!

Note: use long to prevent overflow.

#include <iostream>#include <cstdlib>#include <cstring>#include <cstdio>using namespace std;long long F[303][303],S[303][303];int main(){for (int i = 0 ; i <= 300 ; ++ i)for (int j = 0 ; j <= 300 ; ++ j)F[i][j] = S[i][j] = 0LL;F[0][0] = 1LL;for (int i = 1 ; i <= 300 ; ++ i)for (int j = 1 ; j <= 300 ; ++ j)for (int k = i ; k <= 300 ; ++ k)F[j][k] += F[j-1][k-i];S[0][0] = 1LL;for (int i = 1 ; i <= 300 ; ++ i)for (int j = 0 ; j <= 300 ; ++ j)S[i][j] = S[i-1][j]+F[i][j];int  N,L1,L2;char buf[256];while (gets(buf)) {int n = sscanf(buf,"%d%d%d",&N,&L1,&L2);if (n > 1) {if (L1 > 300) L1 = 300;if (n > 2) {if (L2 > 300) L2 = 300;if (L1 > L2) cout << 0 << endl;else if (L1) cout << S[L2][N] - S[L1-1][N] << endl;else cout << S[L2][N] << endl;}else cout << S[L1][N] << endl; }else cout << S[N][N] << endl;}return 0;}

UV 10313-pay the price

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.