2014年1月31日

UVa 10721 - Bar Codes

#include <cstdio>
 
long long dp[51][51][51];

int main() {
  dp[0][0][0] = 1;
  int N, K, M;
  while (scanf("%d%d%d", &N, &K, &M) == 3) {
    long long ans = 0;
    for (int n = 1; n <= N; n++) {
      for (int k = 1; k <= K; k++) {
        for (int last = 1; last <= M; last++) {
          dp[n][k][last] = dp[n - 1][k][last - 1];
          if (last == 1) {
            for (int preLast = 0; preLast <= M; preLast++) {
              dp[n][k][last] += dp[n - 1][k - 1][preLast];
            }
          }
          if (n == N && k == K) {
            ans += dp[n][k][last];
          }
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}

沒有留言:

張貼留言