zoukankan      html  css  js  c++  java
  • _bzoj1002 [FJOI2007]轮状病毒【瞎搞】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1002

    这种题真是有毒,很多叼一点的都用matrix tree定理推出了递推公式,也有一些用好几维递推也可以解,然而我一个都看不懂。总结:下次遇到这种题就直接打表找规律,这是坠吼滴!

    #include <cstdio>
    #include <cstring>
    
    const int maxn = 105, mod = 10000;
    
    int n;
    struct gao {
    	int data[100], wei;
    	gao(void) {
    		memset(data, 0, sizeof data);
    		wei = 0;
    	}
    	gao operator+(int aa) const {
    		gao rt;
    		rt.data[0] = aa;
    		for (int i = 0; i < wei; ++i) {
    			rt.data[i] += data[i];
    			if (rt.data[i] >= mod) {
    				rt.data[i] -= mod;
    				++rt.data[i + 1];
    			}
    		}
    		rt.wei = wei + (rt.data[wei]? 1: 0);
    		return rt;
    	}
    	gao operator-(const gao & rhs) const {
    		gao rt;
    		for (int i = 0; i < wei; ++i) {
    			rt.data[i] += data[i] - rhs.data[i];
    			if (rt.data[i] < 0) {
    				rt.data[i] += mod;
    				--rt.data[i + 1];
    			}
    		}
    		rt.wei = wei;
    		while (rt.wei > 0 && !rt.data[rt.wei - 1]) {
    			--rt.wei;
    		}
    		return rt;
    	}
    	gao operator*(int aa) const {
    		gao rt;
    		for (int i = 0; i < wei; ++i) {
    			rt.data[i] += data[i] * aa;
    			rt.data[i + 1] += rt.data[i] / mod;
    			rt.data[i] %= mod;
    		}
    		rt.wei = wei + (rt.data[wei]? 1: 0);
    		return rt;
    	}
    	void print(void) {
    		printf("%d", data[wei - 1]);
    		for (int i = wei - 2; i >= 0; --i) {
    			printf("%04d", data[i]);
    		}
    	}
    } f[maxn];
    
    int main(void) {
    	f[1].data[0] = 1;
    	f[1].wei = 1;
    	f[2].data[0] = 5;
    	f[2].wei = 1;
    	scanf("%d", &n);
    	for (int i = 3; i <= n; ++i) {
    		f[i] = f[i - 1] * 3 - f[i - 2] + 2;
    	}
    	f[n].print();
    	puts("");
    	return 0;
    }
    

      

  • 相关阅读:
    代理模式
    建造者模式
    开源版本 hadoop-2.7.5 + apache-hive-2.1.1 + spark-2.3.0-bin-hadoop2.7整合使用
    Phoenix映射HBase数据表
    使用sqoop将mysql中表导入hive中报错
    数据库索引原理及优化(转载)
    6.JAVA知识点归纳整理
    5.hbase表新增数据同步之add_peer
    mongodb分布式集群搭建
    4.HBASE数据迁移方案(之snapshot):
  • 原文地址:https://www.cnblogs.com/ciao-sora/p/6171476.html
Copyright © 2011-2022 走看看