uva 10081 - Tight Words(dp)
来源:互联网 发布:轮船时刻表查询软件 编辑:程序博客网 时间:2024/06/08 13:58
1、http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1022
2、题目大意:
给定两个数k n
用1-k的数组成一个n个数的序列,如果这个序列每两个相邻的数相差<=1,就记为是tight,求这种序列占总序列的比率
3、题目:
Problem B: Tight words
Given is an alphabet {0, 1, ... , k}, 0 <= k <= 9 . We say that a word of lengthn over this alphabet is tight if any two neighbour digits in the word do not differ by more than 1.Input is a sequence of lines, each line contains two integer numbers k andn, 1 <= n <= 100. For each line of input, output the percentage of tight words of lengthn over the alphabet {0, 1, ... , k} with 5 fractional digits.
Sample input
4 12 53 58 7
Output for the sample input
100.0000040.7407417.382810.101304、代码:
#include<stdio.h>double dp[110][12];//第i个位置填充j的概率int main(){ int k,n; while(scanf("%d%d",&k,&n)!=EOF) { if(k<=1) printf("100.00000\n"); else { for(int i=0;i<=k;i++) dp[1][i]=100.0/(k+1); for(int i=2;i<=n;i++) { for(int j=0;j<=k;j++) { if(j==0) { dp[i][j]=1.0/(k+1)*(dp[i-1][j]+dp[i-1][j+1]); } else if(j==k) { dp[i][j]=1.0/(k+1)*(dp[i-1][j-1]+dp[i-1][j]); } else { dp[i][j]=1.0/(k+1)*(dp[i-1][j-1]+dp[i-1][j]+dp[i-1][j+1]); } } } double ans=0; for(int i=0;i<=k;i++) { ans+=dp[n][i]; } printf("%.5lf\n",ans); } } return 0;}
- uva 10081 - Tight Words(dp)
- UVA 10081 - Tight Words (数论 dp)
- Uva 10081 Tight words (概率DP)
- uva 10081 - Tight Words(dp)
- UVa 10081 Tight Words (DP)
- uva 10081 (Tight Words) (DP)
- UVA 10081 Tight Words
- UVA 10081 Tight Words
- UVa 10081 - Tight Words
- UVa 10081 - Tight Words
- UVA10081 - Tight Words(dp)
- UVA10081 Tight Words(dp)
- Uva 10081 - Tight Words 解题报告(递推)
- ZOJ 1883 Tight Words(概率DP)
- Tight words (dp)
- Tight Words(数位DP)
- POJ 2537 Tight words DP
- fzoj 1342 Tight Words(DP:递推)
- PreparedStatement的用法
- 利用Node节点来实现3行5列的图片相册
- Android实现九宫格
- java常用包
- 内存分配方式有三种
- uva 10081 - Tight Words(dp)
- linux系统备份与还原
- 对android内置的sqlLite数据库进行增、删、改、查操作
- 关于delphi中用adoquery进行模糊查询
- const修饰
- JS当中Dom实现图片的轮换
- hdu 1068 Girls and Boys 解题报告
- 判断一个点是否在三角形内(面积法,三个点求三角形面积)
- js实现图片轮换效果