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 ...
随机推荐
- (转)sqlplus中文显示乱码的问题
sqlplus中文显示乱码的问题 2010-07-19 11:33:26 分类: LINUX 在windows下sqlplus完全正常,可是到linux下,sqlplus中文显示就出问题了,总是显示“ ...
- Unity手撸2048小游戏——背景文字控制
今天继续昨天的计划吧 1.新建项目.场景命名啥的都不说了吧. 2.直接开始新建一个Image,顺便把Image改名成Chessman 3.选中Image新建一个Text对象,调整下大小位置.这样就算完 ...
- Web String path问题
request.getContextPath()"下方出现了红色的波浪线,提示的错误信息是 "The method getContextPath() from the type H ...
- Tomcat目录映射设置
方法一: \conf\server.xml <Host>内插入<Context path="虚拟目录" docBase="文件目录" /> ...
- Swift_2基础
mport Foundation // MARK: - ?和!的区别// ?代表可选类型,实质上是枚举类型,里面有None和Some两种类型,其实nil相当于OPtional.None,如果非nil相 ...
- 1012. The Best Rank (25)
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- Google C++ Style Guide
Background C++ is one of the main development languages used by many of Google's open-source project ...
- node与socket.io搭配小例子-转载
//服务端代码 io = require('socket.io').listen(app), fs = require('fs'), cookie=require('cookie'); request ...
- 【Java】Annotation_学习笔记
Annotation 1.APT: 访问和处理Annotation的工具统称,即Annotation Process Tool. 2.java.lang下提供的五种基本Annotation: @Ove ...
- Python之路 day2 字符串/元组/列表/字典互转
#-*-coding:utf-8-*- #1.字典 dict = {'name': 'Zara', 'age': 7, 'class': 'First'} #字典转为字符串,返回:<type ' ...