poj1579 Function Run Fun

March 8, 2013
POJ

Description Input Output Sample Input Sample Output


#include <cstdio>
#include <cstring>
using namespace std;
int ww[22][22][22];
int w(int a, int b, int c){
  if (a <= 0 || b <= 0 || c <= 0) return 1;
  if (a > 20 || b > 20 || c > 20) return w(20, 20, 20);
  if (ww[a][b][c] > 0) return ww[a][b][c];
  if (a < b && b < c) return ww[a][b][c] = w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c);
  else return ww[a][b][c] = w(a-1, b, c) + w(a-1, b-1, c) + w(a-1, b, c-1) - w(a-1, b-1, c-1);
}
int main(void){
  int a, b, c;
#ifndef ONLINE_JUDGE
  freopen("poj1759.in", "r", stdin);
#endif
  while (~scanf("%d%d%d", &a, &b, &c)){
    if (a == b && b == c && c == -1) break;
    memset(ww, -1, sizeof(ww));
    printf("w(%d, %d, %d) = %d\n", a, b, c, w(a, b, c));
  }
  return 0;
}

基本思想就是标记的思想,避免重复计算,水题,看了讨论板学会的,突然发现好久不做水题了…… 有一个事情,就是敲代码的时候,要认真,千万要避免打字错误……次奥,超级让人崩溃的

comments powered by Disqus