Title: give you n a continuous array of long-form elements that can be black or white, and the next barrel-heavy color as a part;
Ask to divide n units into k parts, each of which does not exceed M's fractional numbers.
Analysis: Motion plan, DP. Use the dynamic modeling to find the relationship between the last number added and the previous set.
Definition state: F (i,j,k) is divided into J for I units, each part is not exceeding the K-fractional method;
Transfer equation: F (i,j,k) = SUM (f (i-p,j-1,k)) {1≤p≤k};
Say: The numbers are bigger Oh, note use long long to prevent overflow ╮(╯▽╰)╭.
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace Std;long long f[55][55][55];//f (I. J, k) = SUM (f (i-p, j-1, k) p = 1..K) int main () {for (int i = 0; i <; + + i) for (int j = 0; J < N; + + j) for (int k = 0; k < Wuyi; + + k) F[i][j] [K] = 0ll;for (int i = 0; i <; + + i) f[0][0][i] = 1ll;for (int i = 1; i < Wuyi; + + i) for (int j = 1; j < Wuyi; + + j for (int k = 1; k < n, + + K) for (int p = 1; p <= k && p <= i; + + P) f[i][j][k] + = F[i-p][j-1][k];int n,k , M;while (Cin >> n >> k >> m) cout << f[n][k][m] << Endl; return 0;}
UVa 10721-bar Codes