uva 10313 - Pay the Price
2013-06-21 21:40
267 查看
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main{ public static void main (String [] args) throws Exception { Scanner scan = new Scanner(System.in); long dp[][] = new long[301][301]; for(int i=0;i<301;i++){ dp[0][i] = 1; } for(int i=1;i<301;i++){ for(int j=1;j<301;j++){ dp[i][j] = (i>=j?dp[i-j][j]:0)+dp[i][j-1]; } } while(scan.hasNextLine()){ String s = scan.nextLine(); s = s.trim(); if(s.length()==0) return; String arr[] = s.split(" "); int n = Integer.parseInt(arr[0]); int start = 0; int end = 0; if(arr.length==1){ end = n; } if(arr.length==2){ end = Integer.parseInt(arr[1]); } if(arr.length==3){ start = Integer.parseInt(arr[1]); end = Integer.parseInt(arr[2]); } if(end>n) end = n; if(start-1<0) start = 1; if(n==0) System.out.println(1); else System.out.println(dp [end]-dp [start-1]); } } }
这题怎么说呢,貌似TM有个定理,用J个或者少于J个数组成一个大数的方法和用最大为J的数组成大数方法总数一样。
然后JB这题变成了完全背包。。。还可以用滚动数组优化
其实不知道定理也可以拿个N立方的dp公式来推,就是K再循环一次,悲剧的是我N立方的公式退错了。。。
相关文章推荐
- UVa 10313 Pay the Price (DP&整数拆分)
- 解题报告(一):uva 10313 - Pay the Price (dp)
- UVa 10313 - Pay the Price
- UVA 10313 Pay the Price
- uva 10313 Pay the Price
- UVA - 10313 Pay the Price
- UVA 10313 Pay the Price
- dp(整数拆分 uva10313 - Pay the Price)
- uva 10313 Pay the Price
- uva 10313 Pay the Price (DP)
- UVA 10313 Pay the Price(数字分解DP)
- UVa 10313 Pay the Price(类似数字分解DP)
- UVA10313- Pay the Price
- UVA - 10313 Pay the Price 整数的划分问题 01背包
- UVA 10313 Pay the Price
- UVA - 10313Pay the Price(完全背包)
- uva 10313 Pay the Price(完全背包)
- UVA - 10313 Pay the Price
- UVA - 10313 Pay the Price
- uva 10313 Pay the Price(完全背包)