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 ...
随机推荐
- EXCEL如何提取文字中包含的数字?
方法1:=IF(ISERROR(FIND("-",A1)),"","-")&MID(SUM(MID(101&A1,2+LAR ...
- Jboss配置之数据源密码配置密文--EncryptingDataSourcePasswords
local-tx-datasource:最常用的数据源配置,该连接池的连接管理器是LocalTxConnectionManager,只支持本地事务,不适合做分布式事务.以mssql为例如下:如果密码按 ...
- CentOS搭建NodeJS环境
事件驱动,承受高并发……这些耀眼的光环,使前端开发者不能不去学习NodeJS. 今天就在开发环境把NodeJS搭建起来了. 1. 下载node wget http://nodejs.org/dist/ ...
- XAF视频教程来啦,已出15课
第一到第七课在这里: http://www.cnblogs.com/foreachlife/p/xafvideo_1_6.html 视频地址:http://i.youku.com/i/UMTI5OTE ...
- 调用微信JsAPI端获取位置
public partial class test : BasePage { protected test() { AccessPage = PageWebType.WX; } protected s ...
- footer绝对定位但是不在页面最下边解决方案
方案一 html { height: 100%; } body { position: relative; min-height: 100%; box-sizing: border-box; padd ...
- spring+redis
配置 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www ...
- js和jquery获取当前对象的子元素
开发中经常遇到需要获取ul下的il对象,个人总结了js和jquery的方法. HTML片断: <ul class="box"> <li>子元素1</l ...
- 两个list 合并成新一个list
- js判断中文
var reg = /^[\u4E00-\u9FA5]+$/;if(!reg.test(keywordscn)){ alert('请填写中文') return false;}