project euler 113

对于1个数字,如果他数位不减或者不增称为bouncy number,比如1233,33210。统计1~10^100中的bouncy number
 
思路:分为两种计算

1.这个数中只出现了一个数字,那么对于i位的数字有9种,故总计有9 * 100种

2.这个数中至少出现两个数字,分别按位数计算不减的数和不增的数
以不减的数为例,枚举首数字j和尾数字k(j < k),
j = a1 <= a2 <= a3 <= a4 <= a5 <= … <= am = k
令x1 = a2 - a1,x2 = a3 - a2, x3 = a4 - a3, …, xm - 1 = am - am-1。
x1 + x2 + x3 + … + xm-1 = k - j 解不定方程的解,C(k - j + m - 2, k - j)
不增的数同理
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger; public class Main {
BigInteger bi(int x) {
return BigInteger.valueOf(x);
}
BigInteger comb(int n, int m) {
BigInteger ret = bi(1);
for (int i = n; i >= n - m + 1; -- i) ret = ret.multiply(bi(i));
for (int i = 1; i <= m; ++ i) ret = ret.divide(bi(i));
return ret;
}
void solve() {
int n = 100;
BigInteger ans = bi(9 * n);
for (int i = 2; i <= n; ++ i) {
for (int j = 1; j <= 8; ++ j)
for (int k = j + 1; k <= 9; ++ k) {
ans = ans.add(comb(k - j + i - 2, k - j));
}
}
for (int i = 2; i <= n; ++ i) {
for (int j = 1; j <= 9; ++ j)
for (int k = 0; k <= j - 1; ++ k) {
ans = ans.add(comb(j - k + i - 2, j - k));
}
}
System.out.println(ans);
}
FastScanner cin;
PrintWriter out;
void run() {
cin = new FastScanner();
out = new PrintWriter(System.out);
solve();
out.flush();
}
class FastScanner {
BufferedReader br;
StringTokenizer st;
boolean hasNext; public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
hasNext = true;
} // public FastScanner(String s) {
// try {
// br = new BufferedReader(new FileReader(s));
// } catch (FileNotFoundException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// hasNext = true;
// } public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
hasNext = false;
return "##";
}
}
return st.nextToken();
}
String next = null;
public boolean hasNext() {
next = nextToken();
return hasNext;
}
public int nextInt() {
if (next == null) next = nextToken();
String more = next;
next = null;
return Integer.parseInt(more);
}
public long nextLong() {
return Long.parseLong(nextToken());
} public double nextDouble() {
return Double.parseDouble(nextToken());
}
}
public static void main(String[] args) {
new Main().run();
}
}

project euler113的更多相关文章

  1. .NET Core系列 : 2 、project.json 这葫芦里卖的什么药

    .NET Core系列 : 1..NET Core 环境搭建和命令行CLI入门 介绍了.NET Core环境,本文介绍.NET Core中最重要的一个配置文件project.json的相关内容.我们可 ...

  2. 记一个mvn奇怪错误: Archive for required library: 'D:/mvn/repos/junit/junit/3.8.1/junit-3.8.1.jar' in project 'xxx' cannot be read or is not a valid ZIP file

    我的maven 项目有一个红色感叹号, 而且Problems 存在 errors : Description Resource Path Location Type Archive for requi ...

  3. ASP.NET Core project.json imports 是什么意思?

    示例代码: "frameworks": { "netcoreapp1.0.0": { "imports" : "portable- ...

  4. PhpStorm和WAMP配置调试参数,问题描述Error. Interpreter is not specified or invalid. Press “Fix” to edit your project configuration.

    PhpStorm和WAMP配置调试参数 问题描述: Error. Interpreter is not specified or invalid. Press “Fix” to edit your p ...

  5. Crystal Clear Applied: The Seven Properties of Running an Agile Project (转载)

    作者Alistair Cockburn, Crystal Clear的7个成功要素,写得挺好. 敏捷方法的关注点,大家可以参考,太激动所以转载了. 原文:http://www.informit.com ...

  6. CSharpGL(20)用unProject和Project实现鼠标拖拽图元

    CSharpGL(20)用unProject和Project实现鼠标拖拽图元 效果图 例如,你可以把Big Dipper这个模型拽成下面这个样子. 配合旋转,还可以继续拖拽成这样. 当然,能拖拽的不只 ...

  7. Microsoft Visual Studio 2013 — Project搭载IIS配置的那些事

    前段时间在改Bug打开一个project时,发生了一件奇怪的事,好好的一直不能加载solution底下的这个project,错误如下图所示:大致的意思就是这个project的web server被配置 ...

  8. My First Android Application Project 第一个安卓应用

    一.前言: 安卓(Android):是一种基于Linux的自由及开放源代码的操作系统,主要用在移动设备上,如手机.平板电脑.其他的设备也有使用安卓操作系统,比如:电视机,游戏机.数码相机等等. 二.具 ...

  9. ASP.NET Core中的project.json何去何从?

    Shawn Wildermuth (https://wildermuth.com/2016/05/12/The-Future-of-project-json-in-ASP-NET-Core) If y ...

随机推荐

  1. c#判断DatagridView表里是否有某个字段

    if (DatagridView.Columns.Contains("旧ID"))                {                   有             ...

  2. 题解——洛谷P3128 [USACO15DEC]最大流Max Flow

    裸的树上差分 因为要求点权所以在点上差分即可 #include <cstdio> #include <algorithm> #include <cstring> u ...

  3. 论文阅读: End-to-end Learning of Action Detection from Frame Glimpses in Videos

      End-to-End Learning of Action Detection from Frame Glimpses in Videos  CVPR 2016  Motivation:    本 ...

  4. mybatis配置文件namespace用法总结

    本文为博主原创,未经允许不得转载: 由于在应用过程中,发现namespace在配置文件中的重要性,以及配置的影响,在网上看了很多博客,发现很多人对namespace存在误解, 所以总结一下namesp ...

  5. 【译】第45节---EF6-索引属性

    原文:http://www.entityframeworktutorial.net/entityframework6/index-attribute-in-code-first.aspx Entity ...

  6. Spring-json依赖

    <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jacks ...

  7. 前端分页插件bootstrapPaginator的使用

     引入bootstrap-paginator.js <table class="table table-striped table-bordered table-hover dataT ...

  8. 完美解决百度网盘、浏览器下载限速问题proxyee-down(附带win破解版云盘)

    win版破解云盘 下载: <PanDownload> 使用文档: <PanDownload使用> Mac方法 限速.限速! 平时下载东西限速倒无所谓,遇到急一点的.盯着80km ...

  9. hiho #1196 : 高斯消元·二

    #1196 : 高斯消元·二 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在上一回中,小Hi和小Ho趁着便利店打折,买了一大堆零食.当他们结账后,看到便利店门口还有其 ...

  10. 安装ik分词器以及版本和ES版本的兼容性

    一.查看自己ES的版本号与之对应的IK分词器版本 https://github.com/medcl/elasticsearch-analysis-ik/blob/master/README.md 二. ...