http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2370

难题锻炼思维,水题锻炼细心。

这个题有两个需要注意的地方

1,关于前导零

2,高精度

代码:

import java.math.BigInteger;
import java.util.Scanner; public class Main { /**
* @param args
*/
static final int N=2005;
public static void main(String[] args) {
// TODO Auto-generated method stub
long c[]={0,0,1,1,1,3,3,1};
//long [] c = new long[8];
BigInteger [] sum=new BigInteger[N];
sum[0]=BigInteger.ONE;
for(int i=1;i<N;++i){
sum[i]=BigInteger.ZERO;
}
for(int i=2;i<N;++i){
for(int j=2;j<=7&&i-j>=0;++j){
sum[i]=sum[i].add(sum[i-j].multiply(BigInteger.valueOf(c[j])));
}
if(i==6){
sum[i]=sum[i].subtract(BigInteger.ONE);
}
}
sum[0]=BigInteger.ZERO;
sum[6]=sum[6].add(BigInteger.ONE);
for(int i=1;i<N;++i){
sum[i]=sum[i].add(sum[i-1]);
}
int k;
Scanner in = new Scanner(System.in);
while(in.hasNext()){
k=in.nextInt();
System.out.println(sum[k]);
}
in.close();
} }

UVa 11375 - Matches的更多相关文章

  1. uva 11375 Matches (递推)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  2. 【Java】【高精度】【递推】UVA - 11375 - Matches

    d[i+c[j]]+=d[i](c[j]是拼成j所需的火柴数) d[0]=1: 别忘了不能有前导零,所以当i为零时,不要尝试去拼成零.反而应该在n>=6时,最后给答案加1(单独拼出0). imp ...

  3. uva 11357 Matches

    // uva 11357 Matches // // 题目大意: // // 给你n个火柴,用这n个火柴能表示的非负数有多少个,不能含有前导零 // // 解题思路: // // f[i] 表示正好用 ...

  4. uva 11375

    思路是刘书上的 但是个高精度  java 大数 ~~ import java.util.*; import java.io.*; import java.math.BigInteger; public ...

  5. UVA 11375 高精度Bign类

    求火柴的组成的数字最多能组成多少种数字,典型的递推问题 但是因为结果巨大,要用高精度运算 一开始手写高精度,不仅挫的要死,最后还WA了. 最后学了一下白书上面的bign类,相当方便啊. #includ ...

  6. BigInteger

    首先上模板(不断更新中...)(根据刘汝佳AOAPCII修改) #include <iostream> #include <sstream> #include <cstd ...

  7. uva11357 Matches

    Matches UVA - 11375 题意: 给你n根matches, 你可以拼出多少个数字0~9. 不必全部用完. 解题思路: 1. 计数题, 本题可以用图来理解. 把"已经使用了i根m ...

  8. UVa 340 Master-Mind Hints (优化查找&复制数组)

    340 - Master-Mind Hints Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_on ...

  9. keil MDK error: L6236E: No section matches selector - no section 错误

    今天板子刚到,新建的第一个工程就报错了. .\Objects\cse.sct(7): error: L6236E: No section matches selector - no section t ...

随机推荐

  1. bootstrap 图片轮播效果

    <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="http: ...

  2. UIImageView 的contentMode属性

    UIViewContentModeScaleToFill UIViewContentModeScaleAspectFit UIViewContentModeScaleAspectFill UIView ...

  3. java语法糖3 深入剖析Java中的装箱和拆箱

    装箱 在Java SE5之前,如果要生成一个数值为10的Integer对象,必须这样进行: Integer i = new Integer(10); 而在从Java SE5开始就提供了自动装箱的特性, ...

  4. chmod修改文件的权限/chown修改文件和目录的所有者

    ll指令的显示的信息为(当前目录下只有nameservice1一个目录): drwxr-xr-x 3 hdfs hdfs 4096 4月 14 16:19 nameservice1 上述信息分别表示: ...

  5. 数据库事物四大特性-ACID

    事务的:原子性.一致性.分离性.持久性 事物(transaction)是由一些列操作序列构成的执行单元,这些单元要么都做,要么不做,是一个不可分割的工作单元. 数据库事物的四个基本性质(ACID) 1 ...

  6. 解决Win7中第一次HttpWebRequest连接缓慢、超时等问题

    在使用HttpWebRequest的时候发现,第一次连接需要15S左右,我的系统是win7,很崩溃,除了我那个用户可以等待的了,但是第二次,就没有问题了,于是百度之...... http://www. ...

  7. --tags --follow-tags 的区别

    --tags    All refs under refs/tags are pushed, in addition to refspecs explicitly listed on the comm ...

  8. AlphaGo实现原理

    AlphaGo已经打败了李世石9段,如果你也懂它背后的原理,或许某一天你也可以开发出一款AI来打败dota或者LOL的世界冠军. Mastering the game of Go with deep ...

  9. Selenium解决页面元素不在视野范围内的问题

    当需要使用滚动条才能使页面元素显示在视野范围内时,必须用代码处理下,才能对其进行操作. 处理其实也很简单,就是调用JS函数. driver.executeScript("arguments[ ...

  10. 打开Eclipse时出现"The Eclipse executable launcher was unable to locate its companion shared library"情况的解决办法

    在网上有坑,各种解决方法都有,但似乎我这台64位机器不太给面子,都不能解决: 结果自己找到了解决办法,总结了一下,大多数软件出问题,如果卸载了重新装还是出现问题,一般都是注册表残留的问题: 将ecli ...