合肥工业大学oj 1267 Function

//使用递归一定超时,所以改为dp
//这是一种非常规的dp
#include<iostream>
#include<string.h>
using namespace std;

int dp[54][54][54];

int function(int a, int b, int c){
  if(a > 0 && b > 0 && c > 0 && dp[a][b][c] > 0) return dp[a][b][c];
  if(a < 0 || b < 0 || c < 0) return 2;
  else if(a > 50 || b > 50 || c > 50) return 1;
  else return dp[a][b][c] = ((function(a + 1, b + 2, c + 3)) % 10000007 + (function(a - 3, b - 2, c - 1)) % 10000007);
}

int main(){
  memset(dp, -1, sizeof(dp));
  int a,b,c;
  while(cin >> a >> b >> c){
    if(a < 0 || b < 0 || c < 0) cout << 2 << endl;
    else if(a > 50 || b > 50 || c > 50) cout << 1 << endl;
    else cout<<function(a, b, c) % 10000007 << endl;
  }
  
  return 0;
}

//presented by 大吉大利,今晚AC

猜你喜欢

转载自blog.csdn.net/lalala_HFUT/article/details/87967563