zoukankan      html  css  js  c++  java
  • POJ 1189 模拟/DP

    没什么好说的,照着题目模拟就好~

    (别告诉我你不知道这个是中文题)

    View Code
     1 #include <cstdio>
     2 #include <cstring>
     3 #include <cstdlib>
     4 #include <iostream>
     5 
     6 #define N 60
     7 
     8 using namespace std;
     9 
    10 int n,m,num;
    11 bool tra[N*N];
    12 long long fz,fm,ubt,dp[N][N];
    13 
    14 long long gcd(long long a,long long b)
    15 {
    16     long long mod;
    17     while(b)
    18     {
    19         mod=a%b;
    20         a=b; b=mod;
    21         //cout<<a<<"   "<<b<<endl;
    22     }
    23     return a;
    24 }
    25 
    26 void go()
    27 {
    28     num=0;
    29     char str[4];
    30     for(int i=1;i<=n;i++)
    31         for(int j=1;j<=i;j++)
    32         {
    33             scanf("%s",str);
    34             if(str[0]=='*') tra[++num]=true;
    35             else tra[++num]=false;
    36         }    
    37     //for(int i=1;i<=num;i++) printf("%d    %d\n",i,tra[i]);
    38     
    39     memset(dp,0,sizeof dp);
    40     dp[1][1]=1LL<<n;
    41     for(int i=1,sbh;i<=n;i++)
    42     {
    43         sbh=(i*(i-1))/2;
    44         for(int j=1;j<=i;j++)
    45         {
    46             if(tra[j+sbh])
    47             {
    48                 dp[i+1][j]+=dp[i][j]/2;
    49                 dp[i+1][j+1]+=dp[i][j]/2;
    50             }
    51             else dp[i+2][j+1]+=dp[i][j];
    52         }
    53     }
    54     
    55     fz=dp[n+1][m+1];
    56     fm=1LL<<n;
    57     
    58 
    59     ubt=gcd(fm,fz);
    60     if(fz==0) fm=ubt=1;
    61     printf("%lld/%lld\n",fz/ubt,fm/ubt);
    62 }
    63 
    64 int main()
    65 {
    66     while(scanf("%d%d",&n,&m)!=EOF)
    67     {
    68         go();
    69     }
    70     return 0;
    71 }
    没有人能阻止我前进的步伐,除了我自己!
  • 相关阅读:
    检测mysq组复制的脚本
    centos7安装NFS
    mysql组复制安装
    springboot+VUE(一)
    redis集群配置
    codevs 3139 栈练习3
    codevs 3138 栈练习2
    codevs 2622 数字序列
    codevs 1054 电梯
    codevs 1507 酒厂选址
  • 原文地址:https://www.cnblogs.com/proverbs/p/2715953.html
Copyright © 2011-2022 走看看