动态规划,递推,高精度(Matches,uva 11375)
2016-11-03 21:37
399 查看
第二次用JAVA交题。还是写得一脸懵逼。
给点链接
JAVA高精度基础
http://blog.csdn.net/l04205613/article/details/6873991
第一次交JAVA
http://blog.csdn.net/xl2015190026/article/details/52887202
动态规划用刷表法,缺点是要先全部置0,优点是转移简单,特别是这句if(!(i==0&&j==0)&&i+c[j]<=2000)好棒。
然后一直错因为把dp[i+c[j]]=dp[i+c[j]].add(dp[i]);写成dp[i+c[j]].add(dp[i]);。。。。。。。
代码
import java.util.*;
import java.math.*;
public class Main {
Main()
{
int c[]={6,2,5,5,4,5,6,3,7,6};
BigInteger dp[]=new BigInteger[2010];
BigInteger f[]=new BigInteger[2010];
for(int i=0;i<=2000;i++)
{
dp[i]=new BigInteger("0");
f[i]=new BigInteger("0");
}
dp[0]=new BigInteger("1");
for(int i=0;i<=2000;i++)
{
for(int j=0;j<10;j++)
{
if(!(i==0&&j==0)&&i+c[j]<=2000)
dp[i+c[j]]=dp[i+c[j]].add(dp[i]);
}
if(i>0)
{
f[i]=f[i].add(f[i-1]);
f[i]=f[i].add(dp[i]);
}
}
Scanner in=new Scanner(System.in);
while(in.hasNextInt())
{
int a=in.nextInt();
if(a==0) System.out.println("0");
else if(a<6) System.out.println(f[a]);
else System.out.println(f[a].add(new BigInteger("1")));
}
in.close();
}
public static void main(String[] args)
{
new Main();
}
}
给点链接
JAVA高精度基础
http://blog.csdn.net/l04205613/article/details/6873991
第一次交JAVA
http://blog.csdn.net/xl2015190026/article/details/52887202
动态规划用刷表法,缺点是要先全部置0,优点是转移简单,特别是这句if(!(i==0&&j==0)&&i+c[j]<=2000)好棒。
然后一直错因为把dp[i+c[j]]=dp[i+c[j]].add(dp[i]);写成dp[i+c[j]].add(dp[i]);。。。。。。。
代码
import java.util.*;
import java.math.*;
public class Main {
Main()
{
int c[]={6,2,5,5,4,5,6,3,7,6};
BigInteger dp[]=new BigInteger[2010];
BigInteger f[]=new BigInteger[2010];
for(int i=0;i<=2000;i++)
{
dp[i]=new BigInteger("0");
f[i]=new BigInteger("0");
}
dp[0]=new BigInteger("1");
for(int i=0;i<=2000;i++)
{
for(int j=0;j<10;j++)
{
if(!(i==0&&j==0)&&i+c[j]<=2000)
dp[i+c[j]]=dp[i+c[j]].add(dp[i]);
}
if(i>0)
{
f[i]=f[i].add(f[i-1]);
f[i]=f[i].add(dp[i]);
}
}
Scanner in=new Scanner(System.in);
while(in.hasNextInt())
{
int a=in.nextInt();
if(a==0) System.out.println("0");
else if(a<6) System.out.println(f[a]);
else System.out.println(f[a].add(new BigInteger("1")));
}
in.close();
}
public static void main(String[] args)
{
new Main();
}
}
相关文章推荐
- UVa 11375 - Matches (递推 JAVA 高精度)
- Uva 11375 Matches 解题报告(递推+高精度)
- UVA 11375 Matches——递推+高精度
- uva 11375 Matches 递推关系||DP||高精度
- 【Java】【高精度】【递推】UVA - 11375 - Matches
- UVA - 11375 Matches(高精度,递推)
- Matches UVA - 11375 递推+大数 Ingenuous Cubrency UVA - 11137 递推
- UVa 11375 Matches (DP&高精度)
- Matches UVA - 11375 递推+大数 Ingenuous Cubrency UVA - 11137 递推
- 100道动态规划——13 UVA 10163 Storage Keepers 有约束条件下的DP,递推,不能使用结构体作为基本单位
- Matches UVA - 11375 递推+大数 Ingenuous Cubrency UVA - 11137 递推
- Matches UVA - 11375 递推+大数 Ingenuous Cubrency UVA - 11137 递推
- UVA - 11375-Matches-dp+高精度
- Matches UVA - 11375 递推+大数 Ingenuous Cubrency UVA - 11137 递推
- uva 11375 - Matches(递推)
- 动态规划,递推,多段图(Ingenuous Cubrency,uva 11137)
- Matches UVA - 11375 递推+大数 Ingenuous Cubrency UVA - 11137 递推
- uva 11375 Matches (递推)
- Matches UVA - 11375 递推+大数 Ingenuous Cubrency UVA - 11137 递推
- Matches UVA - 11375 递推+大数 Ingenuous Cubrency UVA - 11137 递推