poj 2704 dfs
来源:互联网 发布:2016移动支付数据 编辑:程序博客网 时间:2024/05/16 12:33
import java.util.*;import java.io.*;import java.math.BigInteger;public class Main { static int[][] arr = new int[34][34]; static BigInteger[][] mark = new BigInteger[34][34]; static BigInteger dfs(int n,int x,int y){ if(x==n-1&&y==n-1) return BigInteger.ONE; if(arr[x][y]==0) return BigInteger.ZERO; if(!mark[x][y].equals(BigInteger.ZERO)) return mark[x][y]; BigInteger value = BigInteger.ZERO; if(x+arr[x][y]<n){ mark[x+arr[x][y]][y] = dfs(n,x+arr[x][y],y); value = value.add(mark[x+arr[x][y]][y]); } if(y+arr[x][y]<n){ mark[x][y+arr[x][y]] = dfs(n,x,y+arr[x][y]); value = value.add(mark[x][y+arr[x][y]]); } return value; } public static void main(String[] args) throws Exception { Scanner cin = new Scanner(System.in); while(true){ int num = cin.nextInt(); if(num==-1) break; for(int i=0;i<num;i++){ String t = cin.next(); Arrays.fill(arr[i], 0); Arrays.fill(mark[i], BigInteger.ZERO); for(int j=0;j<num;j++){ arr[i][j] = t.charAt(j)-'0'; } } System.out.println(dfs(num,0,0)); } }}
怎么记忆化dfs 比单调bfs还慢,我哪里写的不好。
- poj 2704 dfs
- DFS POJ
- POJ DFS
- poj 3083 DFS+DFS+BFS
- POJ 1753 ID+DFS
- poj 1950 数字dfs
- poj 1816(trie+dfs)
- POJ 3107 Godfather(DFS)
- poj 3620(DFS)
- poj 1020 DFS
- poj 2362Square(DFS)
- POJ 2676 Sudoku dfs
- POJ 2357 Labyrinth [DFS]
- poj 1011 dfs
- poj 1190 dfs(生日蛋糕)
- poj 1154 dfs
- poj 2192 DFS+剪枝
- 【DFS】POJ 2044
- EMBEDDED_driver_nandflash_&_FPGA_8_14
- emcas 常用快捷键
- 关于ARM汇编程序的理解
- scanf和printf
- 英文ubuntu11.10安装中文输入法ibus的方法
- poj 2704 dfs
- Dropbox刷空间实战
- hdu 2569彼岸
- vs2005如何看到一个对象的内存分布
- 根据身份证号码计算出生日期、年龄、性别(18位)
- EMBEDDED_driver_nandflash_&_FPGA_8_15
- 学生管理系统之删除
- Hibernate JPA
- 根据入职时间计算工龄