UVA 10934(p292)----Dropping water balloons
2016-03-26 19:56
267 查看
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #define debu using namespace std; typedef unsigned long long ULL; int k; ULL n; ULL f[150][100]; void prepare() { memset(f,0,sizeof(f)); for(int i=1; i<=63; i++) for(int j=1; j<=63; j++) f[i][j]=f[i-1][j-1]+1+f[i][j-1]; } int main() { #ifdef debug freopen("in.in","r",stdin); #endif // debug prepare(); while(cin>>k>>n) { if(k==0) break; int ans=-1; k=min(k,63); for(int i=0; i<=63; i++) if(f[k][i]>=n) { ans=i; break; } if(ans!=-1) printf("%d\n",ans); else printf("More than 63 trials needed.\n"); } return 0; }
题目地址:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1875
题解:f[i][j]表示用i个气球实验j次能测试的楼的最高层数,设测试楼层为k。
若在第k层气球破,则前k-1层必须能用i-1个气球j-1次实验测出,即f[i-1][j-1]+1。
若在第k层气球不破,则相当于把第k+1层看作第一层测试,所以在第k层之上还可测试f[i][j-1]次。
综上,f[i][j]=f[i-1][j-1]+1+f[i][j-1]。
相关文章推荐
- Spark是否会替代Hadoop?
- linux创建用户命令
- linux监控与管理常用命令
- 修改Esxi克隆的CentOS的IP地址
- 《高可用MySQL》2 – 单机版MySQL主从配置
- Shell代码规范
- Shell 命令重定向输出
- hadoop 安装配置 Ubuntu 14.04server
- 二、Tomcat
- 关于Linux上下文切换
- Shell脚本自动部署(编译)LAMP平台
- OpenGL画圆
- Apache Options Indexes FollowSymLinks具体解释
- 理解RESTful架构
- 理解RESTful架构
- linux routing software suite
- 电子邮件协议之SMTP、POP3和IMAP
- nginx下yaf路由始终定位到index/index/index下的解决方法
- Linux下如何进行FTP设置
- django apache部署配置