Notice: Undefined index: HTTP_ACCEPT_ENCODING in C:\server\web\www.showyounger.com\s-system.php on line 2
RectPath | 小样儿(ShowYounger)
小样儿,顶呱呱!!![http://www.showyounger.com]
- import java.math.BigInteger;
- import java.util.HashMap;
- import java.util.Map;
-
- public class RectPath {
-
- private static int endX = 0;
- private static int endY = 0;
- private static Map<String, BigInteger> cache = null;
-
- public static void main(String[] args) {
-
- int width = 311;
- int height = 311;
- cache = new HashMap<String, BigInteger>();
-
- BigInteger paths = getPath(width, height);
-
- System.out.println("(0,0)-(" + width + ", " + height + ")=" + paths);
- }
-
- public static BigInteger getPath(int x, int y) {
-
- endX = Math.abs(x);
- endY = Math.abs(y);
-
- return getRectPath(0, 0);
- }
-
- private static BigInteger getRectPath(int startX, int startY) {
-
- if(startX == endX || startY == endY) {
-
- return new BigInteger("1");
- } else {
- if(cache.containsKey(startX + "," + startY)) {
- return cache.get(startX + "," + startY);
- } else {
- BigInteger result = getRectPath(startX + 1, startY).add(getRectPath(startX, startY + 1));
- cache.put(startX + "," + startY, result);
- return result;
- }
- }
- }
-
- }