A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 善良的禽兽 中级黑马   /  2015-9-27 11:36  /  400 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文


#include "cstdio"
#include "cmath"
#include "cstring"
#include "algorithm"
#include "iostream"
#include "vector"
#include "queue"
#include "stack"
#include "set"
#include "map"
#define lson root<<1
#define rson root<<1|1
#define lowbit(i) i&(-i)
#define debug(x) cout<<#x<<"="<<x<<endl;
#define here cout<<endl<<"_______________here "<<endl;
#define INF 0x7f7f7f7f
#define Prime 999983
#define N ***
using namespace std;

int flag[30][30][15];

int dp(int y, int x, int n)
{
           int sum(0);
           if(flag[y][x][n])
                 return flag[y][x][n];
      if(n == 0)
           return y == 15 && x == 15;      

      sum = dp(y - 1, x - 1, n - 1) + dp(y - 1, x, n - 1) + dp(y, x - 1, n - 1) + dp(y, x + 1, n - 1) + dp(y + 1, x, n - 1) + dp(y + 1, x + 1, n - 1);
      flag[y][x][n] = sum;
      return sum;
}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    int T, n;
    scanf("%d", &T);
    while(T--)
    {
             memset(flag, 0, sizeof(flag));
             scanf("%d", &n);
             flag[15][15][0] = 1;
             printf("%d\n",dp(15, 15, n));
    }

     return 0;
}//233ms


#include "cstdio"
#include "cmath"
#include "fstream"
#include "cstring"
#include "algorithm"
#include "iostream"
#include "vector"
#include "queue"
#include "stack"
#include "set"
#include "map"
#define lson root<<1
#define rson root<<1|1
#define lowbit(i) i&(-i)
#define debug(x) cout<<#x<<"="<<x<<endl;
#define here cout<<endl<<"_______________here "<<endl;
#define INF 0x7f7f7f7f
#define LINF 0x7f7f7f7f7f7f7f7f
#define Prime 999983
#define N 15
using namespace std;
long long dp[N][2 * N][2 * N];
int Move[6][2] = {{-1, 0}, {-1, 1}, {0, -1}, {0, 1}, {1, -1}, {1, 0}};

bool judge(int posy, int posx)
{
           if(posy < 0 || posy > 2 * N || posx < 0 || posx > 2 * N)
                      return false;
           return true;
}

void Init()
{
          int posy, posx;
          memset(dp, 0, sizeof(dp));
     dp[0][N][N] = 1;
     for(int i = 1; i < N; i++)
     {
               for(int y = 0; y < 2 * N; y++)
               {
                        for(int x = 0; x < 2 * N; x++)
                        {
                                  for(int j = 0; j < 6; j++)
                                  {
                                             posy = y + Move[j][0];
                                             posx = x + Move[j][1];
                                             if(judge(posy, posx))
                                                   dp[y][x] += dp[i - 1][posy][posx];
                                  }
                        }
               }
     }      
}
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    int T, n;
    Init();
    scanf("%d", &T);
    while(T--)
    {
             scanf("%d", &n);
             printf("%lld\n", dp[n][N][N]);
    }
    return 0;
}//0ms







0 个回复

您需要登录后才可以回帖 登录 | 加入黑马