2013年9月4日

UVa 10912 - Simple Minded Hashing

#include <cstdio>

int main() {
  int L, S, C = 1;
  int dp[27][352][27] = {};
  for (int t = 1; t <= 26; t++) {
    dp[1][t][t] = 1;
  }
  for (int l = 2; l <= 26; l++) {
    for (int s = 351; s; s--) {
      for (int pre = 0; pre < 26; pre++) {
        for (int tail = pre + 1; tail <= 26 && tail <= s; tail++) {
          dp[l][s][tail] += dp[l - 1][s - tail][pre];
        }
      }
    }
  }
  while (scanf("%d%d", &L, &S) && L) {
    int ans = 0;
    if (L <= 26 && S <= 351) {
      for (int t = 1; t <= 26; t++) {
        ans += dp[L][S][t];
      }
    }
    printf("Case %d: %d\n", C++, ans);
  }
  return 0;
}

沒有留言:

張貼留言