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