zoukankan      html  css  js  c++  java
  • poj1671

    题意:一首n行诗,每一行有一种韵律,问这首诗总共可能有多少种韵律排列

    思路:dp or 递推

         f[i][j]表示前i个位置,用j种韵律的方案数

        f[i][j] = f[i-1][j]*j + f[i-1][j-1]

       {其实挺好理解的,如果没出现新的韵律,那么就用前面的j种任意一种韵律来填充,否则就新引入一种韵律}

     1 /*
     2   State:Accpeted
     3   Time:2013-03-07 22:02:23
     4 */
     5 #include <iostream>
     6 #include <cstring>
     7 #include <string>
     8 #include <cstdlib>
     9 #include <cstdio>
    10 #include <algorithm>
    11 #include <cmath>
    12 using namespace std;
    13 const int maxn = 100;
    14 double f[maxn + 1][maxn + 1] , ans[maxn + 1];
    15 int n;
    16 int main(){
    17     freopen("poj1671.in","r",stdin);
    18     freopen("poj1671.out","w",stdout);
    19     for (int i = 1 ;  i <= maxn; ++i){
    20          f[i][1]  =  1;
    21          ans[i] = 1;
    22     }
    23     for (int i = 1 ; i <= maxn; ++i)
    24         for (int j = 2;  j <= i; ++j){
    25            f[i][j] = f[i - 1][j - 1] + f[i - 1][j] * j;
    26            ans[i] += f[i][j];
    27         }
    28     while (1){
    29            scanf("%d",&n);
    30            if (!n) break;
    31            printf("%d %.0f\n", n , ans[n]);
    32     }
    33     fclose(stdin); fclose(stdout);
    34 }

           

  • 相关阅读:
    网站搜索功能lucene
    RabbitMQ消息队列
    zookeeper
    RPC+SOA+dubbo
    石英定时任务-quartz
    通用mapper、图片上传、nginx
    通用mapper和分类实现
    后台商品管理功能实现
    构建框架
    海量数据的并发处理
  • 原文地址:https://www.cnblogs.com/yzcstc/p/2977751.html
Copyright © 2011-2022 走看看