题目链接:传送门

题目大意:已知 a0=0;a1=1; n为偶数 an=a(n/2);n为基数 an=a(n/2)+a(n/2+1);

题目思路:因为n过大,所以要用java高精度,还有最多20组数据,所以记忆化搜索一下

import java.io.*;
import java.math.*;
import java.util.*; public class Main {
public static HashMap<BigInteger, BigInteger> M=new HashMap<BigInteger,BigInteger>();
public static Scanner in=new Scanner(new BufferedInputStream(System.in));
public static void main(String args[]){
M.put(BigInteger.valueOf(0),BigInteger.valueOf(0));
M.put(BigInteger.valueOf(1),BigInteger.valueOf(1));
solve();
in.close();
}
public static void solve(){
int group=in.nextInt();
while(group--!=0){
BigInteger num1=in.nextBigInteger();
BigInteger ans=dfs(num1);
System.out.println(ans);
}
}
public static BigInteger dfs(BigInteger a){
if(M.containsKey(a)) return M.get(a);
BigInteger ta=a;
if(a.mod(BigInteger.valueOf(2)).compareTo(BigInteger.valueOf(1))==0){
a=a.divide(BigInteger.valueOf(2));
BigInteger temp1=dfs(a);
a=a.add(BigInteger.valueOf(1));
BigInteger temp2=dfs(a);
temp1=temp1.add(temp2);
M.put(ta,temp1);
return temp1;
}
else{
a=a.divide(BigInteger.valueOf(2));
BigInteger tt=dfs(a);
M.put(ta,tt);
return tt;
}
}
}

最新文章

  1. laravel框架总结(十) -- 返回值
  2. 用DirectX实现魔方(二)
  3. Mac 显示 Finder 隐藏文件
  4. Java获取服务器网址
  5. CentOS7 安装 mongodb
  6. Java final,static 关键字
  7. Python学习笔记3—字符串
  8. Nginx状态监控
  9. css3之box-sizing
  10. 自动备份多个MOSS站点集的脚本
  11. nfs error
  12. F4107Usart数据处理程序
  13. Go并发模式:管道与取消
  14. GotoAndPlay
  15. &lt;知识整理&gt;树--堆及其应用
  16. swoole异步群发模板消息
  17. 第六章 使用 Bootstrap Typeahead 组件(百度下拉效果)(续)
  18. 追求极致的用户体验ssr(基于vue的服务端渲染)
  19. windows pm2 开机启动
  20. 【wireshark】抓包和文件格式支持

热门文章

  1. SQL 将两个结构相同的表合并到成一个表
  2. Microsoft SQL Server Data Tools - Business Intelligence for Visual Studio 2013 SSIS
  3. 点滴积累【JS】---JS小功能(JS实现侧悬浮浮动)
  4. Atitit&#160;插件机制原理与设计微内核&#160;c#&#160;java&#160;的实现attilax总结
  5. 转-subl配置全栈开发环境
  6. hibernate 在web.xml中配置的作用
  7. extjs增删改查(自己调用extjs)
  8. SlidingMenu开源项目 -- ReadMe.md翻译
  9. Unity3D中uGUI事件系统简述及使用方法总结
  10. git 工作模式