zoukankan      html  css  js  c++  java
  • BZOJ 1005 小明的烦恼 普吕弗序列

       普吕弗序列不难了,是关于树计数的吧(和基尔霍夫不同的是,基尔霍夫是给定了边的情况,而普吕弗序列是给定了每个点的度)!

    理论:

    大致就是这个样子吧!(将就着看吧!毕竟太年轻)。

    结论: http://hzwer.com/3272.html 

    加油!(只是我积了好久的题了,毕竟以前编码能力比较弱,一直没写掉,最后把它写掉了)

      1 #include<cstdio>
      2 #include<iostream>
      3 #include<cstring>
      4 #define mod 10000
      5 #define ll long long
      6 #define rep(i,j,k) for(int i = j; i <= k; i++)
      7 #define down(i,j,k) for(int i = j; i >= k; i--)
      8 #define clr(i,j) memset(i,j,sizeof(i))
      9 using namespace std;
     10  
     11 int prime[500], cnt = 0, num[500]; bool vis[1005];
     12 int a[1005] = {0};
     13 int ans[1005] = {0};
     14  
     15 inline int read()
     16 {
     17     int s = 0, t = 1; char c = getchar();
     18     while( !isdigit(c) ){
     19         if( c == '-' ) t = -1; c = getchar();
     20     }
     21     while( isdigit(c) ){
     22         s =  s* 10 + c - '0'; c = getchar();
     23     }
     24     return s * t;
     25 }
     26  
     27 void getpri()
     28 {
     29     clr(vis,0);
     30     rep(i,2,1005){
     31         if( !vis[i] ) prime[cnt++] = i;
     32         for(int j = 0; j < cnt && prime[j] * i <= 1005; j++)
     33           vis[prime[j]*i] = 1;
     34     }
     35 }
     36  
     37 void chuli(int a,int f)
     38 {
     39     rep(i,2,a){
     40         int x = i;
     41         rep(j,0,cnt-1){
     42             while( x % prime[j] == 0 ) num[j] += f, x /= prime[j];
     43             if( x == 1 ) break;
     44         }
     45     }
     46 }
     47  
     48 void che(int zhi)
     49 {
     50     rep(i,1,ans[0]){
     51         ans[i] *= zhi;
     52     }
     53     rep(i,1,ans[0]){
     54         ans[i+1] += ans[i] / mod;
     55         ans[i] %= mod; 
     56     }
     57     while( ans[ans[0]+1] ) ans[0]++, ans[ans[0]+1] += ans[ans[0]]/mod, ans[ans[0]]%=mod;
     58 }
     59  
     60 void print()
     61 {
     62     down(i,ans[0],1){
     63         if( i == ans[0] ) printf("%d", ans[i] );
     64         else printf("%04d", ans[i]);
     65     }
     66 }
     67  
     68 int main()
     69 {
     70     getpri();
     71     int n = read(), tot = 0, m = 0; ans[0] = 1, ans[1] = 1;
     72     if( n == 1 ){
     73         int x = read();
     74         if( !x ) puts("1");
     75         else puts("0");
     76         return 0;
     77     }
     78     rep(i,1,n){
     79         a[i] = read();
     80         if( !a[i] ){
     81             puts("0"); return 0;
     82         } else if( a[i] == -1 ) m++;
     83         if( a[i] != -1 ) a[i]--, tot += a[i];
     84     }
     85     if( tot > n-2 ) {
     86         puts("0");
     87         return 0;
     88     }
     89     rep(i,1,n){
     90         if( a[i] != -1 )
     91         chuli(a[i],-1);
     92     }
     93     chuli(n-2,1); chuli(n-2-tot,-1);
     94     rep(i,0,cnt-1){
     95         while( num[i]-- ) che( prime[i] );
     96     }
     97     int k = n-2-tot;
     98     while( k-- ){
     99         che(m);
    100     }
    101     print();
    102     cout<<endl;
    103     return 0;
    104 }
  • 相关阅读:
    3配置
    1开机初始化配置
    shell <<EOF
    Sun SPARC Enterprise M5000 启动步骤
    CISCO MDS – Useful ‘Show’ Commands
    oracle 内存不足处理
    mysql 日志类型
    MySQL 学习
    抓取进程中包括其所有线程的iowait时间
    每天网络半小时(MAC数据包在哪里合并的)
  • 原文地址:https://www.cnblogs.com/83131yyl/p/5098747.html
Copyright © 2011-2022 走看看