zoukankan      html  css  js  c++  java
  • 1002: [FJOI2007]轮状病毒

    1002: [FJOI2007]轮状病毒

    Time Limit: 1 Sec  Memory Limit: 162 MB
    Submit: 5691  Solved: 3090
    [Submit][Status][Discuss]

    Description

      轮状病毒有很多变种,所有轮状病毒的变种都是从一个轮状基产生的。一个N轮状基由圆环上N个不同的基原子
    和圆心处一个核原子构成的,2个原子之间的边表示这2个原子之间的信息通道。如下图所示

      N轮状病毒的产生规律是在一个N轮状基中删去若干条边,使得各原子之间有唯一的信息通道,例如共有16个不
    同的3轮状病毒,如下图所示

      现给定n(N<=100),编程计算有多少个不同的n轮状病毒

    Input

      第一行有1个正整数n

    Output

      计算出的不同的n轮状病毒数输出

    Sample Input

    3

    Sample Output

    16

    HINT

    import java.math.BigInteger;
    import java.util.Scanner;
    /* 打表程序(矩阵树定理)
    LL g[205][205];
    LL d[205][205];
    int sign;
    LL n;
    
    void getc(){//求C矩阵
        memset(d,0,sizeof d);
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(i==j) continue;
                if(g[i][j]){
                    d[i][i]++;
                }
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                g[i][j]=d[i][j]-g[i][j];
            }
        }
    }
    
    LL gauss(){//求行列式
        LL ret = 1;
        for(int i=1;i<n;i++){
            for(int j=i+1;j<n;j++){
                while(g[j][i] != 0){
                    LL tt = g[i][i] / g[j][i];
                    for(int k=i;k<n;k++){
                        g[i][k] = g[i][k] -  tt * g[j][k];
                    }
                    for(int k=i;k<n;k++){
                        swap(g[i][k],g[j][k]);
                    }
                    ret = -ret;
    
                }
            }
            if(g[i][i] == 0) return 0;
                ret = ret * g[i][i];
        }
        if(ret < 0) return -ret;
        return ret;
    }
    int main(){
        // freopen("in.txt","r",stdin);
        int t;
        for(n=1;n<=100;n++){
            memset(g,0,sizeof g);
            for(int i=1;i<n;i++)//中心点
                g[i][0]=g[0][i]=1;
            for(int i=1;i<n;i++){
                if(i==n-1)
                    g[i][1]=g[1][i]=1;
                else
                    g[i][i+1]=g[i+1][i]=1;
            }
            getc();
            cout<<"n="<<n-1<<" "<<gauss()<<endl;
        }
        return 0;
    }
    /*
    n=0 1
    n=1 1
    n=2 5
    n=3 16
    n=4 45
    n=5 121
    n=6 320
    n=7 841
    n=8 2205
    n=9 5776
    n=10 15125
    n=11 39601
    n=12 103680
    n=13 271441
    n=14 710645
    n=15 1860496
    n=16 4870845
    n=17 12752041
    n=18 33385280
    n=19 87403801
    n=20 228826125
    n=21 599074576
    n=22 1568397605
    n=23 4106118241
    n=24 10749957120
    n=25 28143753121
    n=26 73681302245
    n=27 192900153616
    n=28 505019158605
    E:ACM源代码BZOJ区赛练习>
    */
    public class Main {
    
        public static void main(String[] args) {
        // write your code here
            int n;
            Scanner in=new Scanner(System.in);
            n=in.nextInt();
            BigInteger a=new BigInteger("1");
            BigInteger b=new BigInteger("5");
            BigInteger pos;
            if(n<3){
                switch (n){
                    case 1:
                        System.out.println("1");
                    case 2:
                        System.out.println("5");
                }
                return ;
            }
            for(int i=3;i<=n;i++){
                pos=b.multiply(new BigInteger("3"));
                pos=pos.subtract(a);
                pos=pos.add(new BigInteger("2"));
                a=b;
                b=pos;
            }
            System.out.println(b);
        }
    }
  • 相关阅读:
    kvm 存储
    centos 磁盘扩容,新建lv
    openStack windows2008 centos6.* img
    openStack icehouse for centos6.4 production Env 实战
    openStack error infos 调试
    iptables 规则预设置为新centos系统
    ubuntu openStack icehouse dashboard theme自定义
    linux c in common use function reference manual
    openStack centos6.4
    ubuntu 常用生产环境部署配置测试调优
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/7569876.html
Copyright © 2011-2022 走看看