1310. ACM Diagnostics
http://acm.timus.ru/problem.aspx?space=1&num=1310
题目中说的 “the lexicographically increasing list”
10 和 2 谁更小呢,我刚开始没管这么多,直接按数的大小算的,把 2 放在了 10 的前面
然后也过了,但是题意是不是这个意思?
思路:
数位DP + 二分
代码:
import java.math.BigInteger;
import java.util.Scanner; public class Main { /**
* @param args
*/
static final int N = 105;
static final int M = 55;
static final BigInteger[][][] dp=new BigInteger[N][M][M];
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
for(int i=0;i<N;++i){
for(int j=0;j<M;++j){
for(int l=0;l<M;++l){
dp[i][j][l]=BigInteger.ZERO;
}
}
}
int n,m,k;
BigInteger b;
n=in.nextInt();
m=in.nextInt();
k=in.nextInt();
b=in.nextBigInteger();
b=b.add(BigInteger.ONE);
dp[0][1][0]=BigInteger.ONE;
for(int i=0;i<n;++i){
for(int l=0;l<k;++l){
BigInteger tmp=BigInteger.ZERO;
for(int j=1;j<=m;++j){
tmp=tmp.add(dp[i][j][l]);
}
for(int w=1;w<=m;++w){
dp[i+1][w][(l+w)%k]=dp[i+1][w][(l+w)%k].add(tmp);
}
}
}
BigInteger l=BigInteger.ZERO;
BigInteger r =BigInteger.valueOf(m).pow(n).subtract(BigInteger.ONE); while(l.compareTo(r)<=0){
BigInteger mid=l.add(r).divide(BigInteger.valueOf(2L));
BigInteger tmp=gnum(mid,n,m,k); if(tmp.compareTo(b)>=0){
r=mid.subtract(BigInteger.ONE);
}
else{
l=mid.add(BigInteger.ONE);
}
}
int[] a = new int[n];
BigInteger M = BigInteger.valueOf((long)(m));
for(int i=0;i<n;++i){
a[i]=l.mod(M).intValue()+1;
l=l.divide(M);
}
for(int i=n-1;i>=0;--i){
System.out.print(a[i]);
if(i>0)System.out.print(" ");
}
System.out.println(); }
public static BigInteger gnum(BigInteger mid,int n,int m,int mod){
BigInteger M = BigInteger.valueOf((long)(m));
int[] a = new int[n];
for(int i=0;i<a.length;++i){
a[i]=mid.mod(M).intValue()+1;
mid=mid.divide(M);
}
BigInteger tmp=BigInteger.ZERO;
int k=0;
for(int i=n-1;i>=0;--i){
for(int j=a[i]-1;j>=1;--j){
tmp=tmp.add(dp[i+1][j][k]);
}
if(i==0){
tmp=tmp.add(dp[i+1][a[i]][k]);
}
k=( (k-a[i])%mod+mod)%mod;
}
return tmp;
} }
1310. ACM Diagnostics的更多相关文章
- 杭电ACM分类
杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...
- [xdoj] 1310 DSKer的卡牌游戏
http://acm.xidian.edu.cn/problem.php?id=1310 1. 这道题可以类比括号匹配,YY和yy是两组可以匹配的信号,当然要注意逻辑是否正确,一开始进行括号匹配算法的 ...
- SCNU ACM 2016新生赛决赛 解题报告
新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...
- ASP.NET Core 中间件Diagnostics使用
ASP.NET Core 中间件(Middleware)Diagnostics使用.对于中间件的介绍可以查看之前的文章ASP.NET Core 开发-中间件(Middleware). Diagnost ...
- SCNU ACM 2016新生赛初赛 解题报告
新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
- acm结束了
最后一场比赛打完了.之前为了记录一些题目,开了这个博客,现在结束了acm,这个博客之后也不再更新了. 大家继续加油!
- 关于ACM的总结
看了不少大神的退役帖,今天终于要本弱装一波逼祭奠一下我关于ACM的回忆. 从大二上开始接触到大三下结束,接近两年的时间,对于大神们来说两年的确算不上时间,然而对于本弱来说就是大学的一半时光.大一的懵懂 ...
- 第一届山东省ACM——Phone Number(java)
Description We know that if a phone number A is another phone number B’s prefix, B is not able to be ...
- 第一届山东省ACM——Balloons(java)
Description Both Saya and Kudo like balloons. One day, they heard that in the central park, there wi ...
随机推荐
- jquery.validate使用 - 自定义错误信息
自定义错误消息的显示方式 默认情况下,验证提示信息用label元素来显示, 并且会添加css class, 通过css可以很方便设置出错控件以及错误信息的显示方式. /* 输入控件验证出错*/form ...
- 2.ReactNative Properties|States|Styles 笔记
原文地址:http://reactnative.cn/docs/0.31/props.html#content 1. property: 如下代码所示 import React, { Componen ...
- VBA中方法传参
将变量做为参数传递给方法 Sub Test() Dim a As Integer a = Add a Debug.Print a '引用传递,a的值发生了变化,输出101 End Sub Functi ...
- 【树莓派】【转】将树莓派Raspberry Pi设置为无线路由器(WiFi热点AP,RTL8188CUS芯片)
下文为转载,文章转自:http://wangye.org/blog/archives/845/,仅供本次学习实践参考. 最近又开始折腾起Raspberry Pi来了,因为某处上网需要锐捷拨号,于是我就 ...
- [Unity] Android插件
1> 编写eclipse android代码. 2> 把unity下class.jar拷入eclipse libs目录下, 工程中右键build path, add to build pa ...
- road习题(一)
答案:[D] 答案:[C] 分析需要靠人 答案:[B] 答案:[B] c语言本身支持自定义函数 答案:[B] Virtual User Generator:是一个脚本开发组件 说白了就是虚拟机用户发生 ...
- jquery.trim() vs JS.trim()
如果你在IE8浏览器下开发网站,其实这是个假命题,因为原生的javascript 并不支持 .trim()方法,如果你写了类似document.getElementByID().trim();的代码, ...
- java第一天
今天完成的事情: [主线] 1.什么是接口??? 接口(interface)是类与类之间的一种约定,一般而言,实现某个接口,意味着该类必须实现接口中的所有方法. 2.接口的特性. ...
- go并发和并行
Go语言的并发和并行 不知道你有没有注意到一个现象,还是这段代码,如果我跑在两个goroutines里面的话: var quit chan int = make(chan int) func loop ...
- caroufredsel 参数
caroufredsel 参数 参数列表:参数名 默认值 说明circular true 循环模式,true为无限循环,false为单轮循环.infinite ...