POJ 2413(DP)
来源:互联网 发布:信用证是什么意思知乎 编辑:程序博客网 时间:2024/06/01 22:21
题意:蜜蜂在蜂巢(由六边形拼成的平面)里移动一定步数,求路径数(走法不同的相同认为是不同路径)
要点:由于路径可以重叠,即(x,y)是由四周六个方位移动而来,这可以确定状态;而步数的统计可以由层数代替,从而确定阶段,转移方程则是
dp[t][i][j]=dp[t-1][i-1][j]+dp[t-1][i-1][j-1]+dp[t-1][i][j+1]+dp[t-1][i][j-1]+dp[t-1][i+1][j]+dp[t-1][i+1][j+1]//t为步数,i,j为坐标
这是一个双重状态的DP,三维数组可以作为这种DP的工具
建图时要注意,某点对应的六个坐标不能随便定,但是定法不只一种——可以先确定某些对应方向的x,y变化方式,再在周围点假设按照规则移动,可以推断出剩下的定法
代码:
#include <iostream>#include<cstdio>#include<string>#include<cstring>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue>#include<stack>//#include<bits/stdc++.h>using namespace std;const int MAXN = 35;const int INF = 100010;int dp[MAXN][MAXN][MAXN];int n;int main(){ int T; scanf("%d",&T); while(T--) { scanf("%d",&n); memset(dp,0,sizeof dp); dp[0][15][15]=1; for(int t=1;t<=n;t++) for(int i=1;i<30;i++) for(int j=1;j<30;j++) dp[t][i][j]=dp[t-1][i-1][j]+dp[t-1][i-1][j-1]+dp[t-1][i][j+1]+dp[t-1][i][j-1]+dp[t-1][i+1][j]+dp[t-1][i+1][j+1]; printf("%d\n",dp[n][15][15]); } return 0;}
0 0
- POJ 2413(DP)
- poj dp
- 【dp】POJ
- 【dp】POJ
- [DP] POJ
- [DP] POJ
- [DP] POJ
- 【dp】POJ
- POJ 3670 && POJ 3671 (dp)
- 【DP】 POJ 1080
- poj 1163经典DP
- poj 1088 滑雪(DP)
- poj 1770 树形dp
- POJ 1179 Polygon(DP)
- POJ 1221 dp
- POJ 1953 DP
- POJ 2033 DP
- POJ 1179 Polygon DP
- 2016多校联合训练赛 第四场1012 Bubble Sort hdu 5775
- sphinx与中文分词coreseek(window)
- bootstrap, boosting, bagging 几种方法的区别与联系
- [正则表达式]-基础语法一 元字符之定位符
- 服务的启动方式
- POJ 2413(DP)
- SDUT 活动选择 1298
- 手工转换中缀式与前、后缀式(转)
- Linux学习--进程概念
- 浅析 Get 和 Post 的区别
- QWidget,QMainWindow和QDialog的区别
- 四、原型模式Prototype(创建型)
- Widnows bat 编译VS项目
- oracle11g ORA-01017:invalid username/password:logon denied