uva 10254 - The Priest Mathematician
2012-08-13 16:09
253 查看
题意:给你四根柱子的汉若塔!求最少移动数!
解法:F(n) = min(2^k - 1 + F(n - k)) (0 <= k < n);问题来了!朴素的打表会TLE!观察F(n) - F(n - 1);
得到特有爱的数列 1, 2 ,2 , 4 ,4 ,4 , 8,8,8, 8, 16, 16, 16, 16, 16, 16,……
于是乎特邪恶的写法:
题目连接:点击打开链接
最有爱滴代码君:
解法:F(n) = min(2^k - 1 + F(n - k)) (0 <= k < n);问题来了!朴素的打表会TLE!观察F(n) - F(n - 1);
得到特有爱的数列 1, 2 ,2 , 4 ,4 ,4 , 8,8,8, 8, 16, 16, 16, 16, 16, 16,……
于是乎特邪恶的写法:
题目连接:点击打开链接
最有爱滴代码君:
import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String [] args) { Scanner cin = new Scanner(System.in); BigInteger[] dp = new BigInteger[10005]; dp[0] = new BigInteger("0"); BigInteger num = new BigInteger("1"); int k = 0, flag = 1; for (int i = 1; i < 10001; i++) { dp[i] = new BigInteger("0"); if (k == flag) { k = 0; flag++; num = num.multiply(BigInteger.valueOf(2)); } k++; dp[i] = dp[i - 1].add(num); } while (cin.hasNext()) { int n = cin.nextInt(); System.out.println(dp ); } } }
相关文章推荐
- UVa Problem 10254 The Priest Mathematician (牧师数学家)
- UVA 10254 - The Priest Mathematician (dp | 汉诺塔 | 找规律 | 大数)
- uva 10254 the priest mathematician
- uva 10254——The Priest Mathematician
- uva 10254 - The Priest Mathematician(dp)
- UVA 10254 - The Priest Mathematician(规律)
- UVA10254 - The Priest Mathematician(找规律)
- UVA 10254 The Priest Mathematician
- 递推+高精度+找规律 UVA 10254 The Priest Mathematician
- UVA 10254-The Priest Mathematician(大数+递推)
- uva 10254 The Priest Mathematician
- UVa Problem Solution: 10254 - The Priest Mathematician
- UVA 10254 - The Priest Mathematician (dp | 汉诺塔 | 找规律 | 大数)
- UVA 10254 The Priest Mathematician
- UVa 10254 - The Priest Mathematician (4柱汉诺塔)
- UVA 10254 十八 The Priest Mathematician
- The Priest Mathematician
- The Priest Mathematician
- uva 357 - Let Me Count The Ways
- UVA 694 - The Collatz Sequence