题意   建设一条河岸的污水处理系统  河岸有n个城市   每一个城市都能够自己处理污水 V   也能够把污水传到相邻的城市处理 >或<   除了你传给我我也传给你这样的情况   其他都是合法的   两端的城市不能传到不存在的城市

令d[i]表示有i个城市时的处理方法数  最后一个城市的处理方法有

1.V 自己处理自己的  与前i-1个城市的处理方法无关  有d[i-1]种方法

2.< 给左边的城市去处理  也与前i-1个城市的处理方法无关  把自己的污水给第i-1个城市即可了  有d[i-1]种方法

3.>V 左边有污水传过来  和自己的一起处理  这时第i-1个城市能够向右传了  假设这样的情况发生的话  那么第i-1个城市肯定不可能是向左传的  但前i-2个城市的处理方法没有影响  所以第i-1个城市向左传的方法有d[i-2]种   然后第i-1个城市不向左传就有d[i-1]-d[i-2]种方法了

所以有递推公式d[i]=3*d[i-1]-d[i-2];

增长速度非常快要用大数处理   大数就用java了

import java.util.*;
import java.math.*;public class Main {public static void main(String args[]) {Scanner in = new Scanner(System.in);BigInteger d[] = new BigInteger[105];d[1] = BigInteger.ONE;d[2] = BigInteger.valueOf(3);for (int i = 3; i <= 100; ++i)d[i] = d[i - 1].multiply(d[2]).subtract(d[i - 2]);while (in.hasNext())System.out.println(d[in.nextInt()]);in.close();}
<span style="font-family:Microsoft YaHei;">}</span>

还有没加大数模版的c++代码

#include<cstdio>
#include<cstring>
using namespace std;
const int N = 105;
int main()
{int d[N] = {0, 1, 3}, n;for (int i = 3; i <= 100; ++i)d[i] = 3 * d[i - 1] - d[i - 2];while (~scanf ("%d", &n))printf ("%d\n", d[n]);return 0;
}
Water Treatment Plants

Description

River polution control is a major challenge that authorities face in order to ensure future clean water supply. Sewage treatment plants are used to clean-up the dirty water comming from cities before being discharged into the river.

As part of a coordinated plan, a pipeline is setup in order to connect cities to the sewage treatment plants distributed along the river. It is more efficient to have treatment plants running at maximum capacity and less-used ones switched off for a period. So, each city has its own treatment plant by the river and also a pipe to its neighbouring city upstream and a pipe to the next city downstream along the riverside. At each city's treatment plant there are three choices:

  • either process any water it may receive from one neighbouring city, together with its own dirty water, discharging the cleaned-up water into the river;
  • or send its own dirty water, plus any from its downstream neighbour, along to the upstream neighbouring city's treatment plant (provided that city is not already using the pipe to send it's dirty water downstream);
  • or send its own dirty water, plus any from the upstream neighbour, to the downstream neighbouring city's plant, if the pipe is not being used.


The choices above ensure that:

every city must have its water treated somewhere and 
at least one city must discharge the cleaned water into the river. 
Let's represent a city discharging water into the river as "V" (a downwards flow), passing water onto its neighbours as ">" (to the next city on its right) or else "<" (to the left). When we have several cities along the river bank, we assign a symbol to each (V, < or >) and list the cities symbols in order. For example, two cities, A and B, can

each treat their own sewage and each discharges clean water into the river. So A's action is denoted V as is B's and we write "VV" ; 
or else city A can send its sewage along the pipe (to the right) to B for treatment and discharge, denoted ">V"; 
or else city B can send its sewage to (the left to) A, which treats it with its own dirty water and discharges (V) the cleaned water into the river. So A discharges (V) and B passes water to the left (<), and we denote this situation as "V<". 
We could not have "><" since this means A sends its water to B and B sends its own to A, so both are using the same pipe and this is not allowed. Similarly "<<" is not possible since A's "<" means it sends its water to a non-existent city on its left.

So we have just 3 possible set-ups that fit the conditions:

         A    B       A > B       A < B V    V           V       V             RIVER~ ~ ~ ~ ~     ~ ~ ~ ~ ~   ~ ~ ~ ~ ~RIVER"VV"        ">V"         "V<"

If we now consider three cities, we can determine 8 possible set-ups. 
Your task is to produce a program that given the number of cities NC (or treatment plants) in the river bank, determines the number of possible set-ups, NS, that can be made according to the rules define above.

You need to be careful with your design as the number of cities can be as large as 100.

Input

The input consists of a sequence of values, one per line, where each value represents the number of cities.

Output

Your output should be a sequence of values, one per line, where each value represents the number of possible set-ups for the corresponding number of cities read in the same input line.

Sample Input

2
3
20

Sample Output

3
8

102334155

本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5064183.html,如需转载请自行联系原作者

POJ 1205 Water Treatment Plants(递推)相关推荐

  1. POJ 2231 Moo Volume(递推、前缀和)

    题外话: POJ 2231 Moo Volume 题意: 解题过程: AC代码: 题外话: emm--第三套题好像综合了其他OJ的题目蛤,那么我就把题目分开了发了蛤蛤-- POJ 2231 Moo V ...

  2. POJ 1737 Connected Graph (大数+递推)

    题目链接: http://poj.org/problem?id=1737 题意: 求 \(n\) 个点的无向简单(无重边无自环)连通图的个数.\((n<=50)\) 题解: 这题你甚至能OEIS ...

  3. POJ 3046 Ant Counting(递推,和号优化)

    计数类的问题,要求不重复,把每种物品单独考虑. 将和号递推可以把转移优化O(1). f[i = 第i种物品][j = 总数量为j] = 方案数 f[i][j] = sigma{f[i-1][j-k], ...

  4. POJ 3734 Blocks (线性递推)

    定义ai表示红色和绿色方块中方块数为偶数的颜色有i个,i = 0,1,2. aij表示刷到第j个方块时的方案数,这是一个线性递推关系. 可以构造递推矩阵A,用矩阵快速幂求解. 1 /********* ...

  5. poj 1205 :Water Treatment Plants (DP+高精度)

    题意:有n个城市,它们由一个污水处理系统连接着,每个城市可以选择 1.将左边城市过来的污水和右边城市过来的污水连同本身的污水排到河里  >V< 2.将左边来的污水连同自己的污水排到右边   ...

  6. POJ 1661 Help Jimmy(递推DP)

    思路: 1. 每个板子有左右两端, dp[i][0], dp[i][1] 分别记录左右端到地面的时间 2. 从下到上递推计算, 上一层的板子必然会落到下面的某一层板子上, 或者地面上 总结: 1. 计 ...

  7. 2287. 【POJ Challenge】消失之物(数组递推\分治优化背包)

    2287. [POJ Challenge]消失之物 这题的思想和P4564 [CTSC2018]假面优化的思想一样,应该反过来说,假面那个题应该是借鉴这题的思路. 显然不能枚举每个物品消失O(n)O( ...

  8. Bailian4017 爬楼梯(POJ NOI0202-3089)【递推】

    爬楼梯 问题链接:POJ NOI0202-3089 爬楼梯 总时间限制: 1000ms 内存限制: 65536kB 描述 树老师爬楼梯,他可以每次走1级或者2级,输入楼梯的级数,求不同的走法数 例如: ...

  9. L. Poor God Water(ACM-ICPC 2018 焦作赛区网络预赛,ac自动机+矩阵快速幂 或 BM线性递推)

    描述 God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells hi ...

最新文章

  1. Oracle 检查点队列和HASH Bucket
  2. 2.4.1 算术逻辑单元ALU与加法器(串行加法器、并行加法器、全加器)
  3. .NET 6 Preview 6 正式发布: 关注网络开发
  4. 【计算机网络】TCP IP通信处理过程
  5. web开发课程培训,10大前端常用算法,学习路线+知识点梳理
  6. 【链接转载保存】Collections.singletonList方法的使用
  7. fcpx插件:Beautiful Slideshow - 时尚简洁图片幻灯片开场
  8. Redis 与 hash (哈希)相关的常用命令
  9. 请概述可视化卷积神经网络的中间输出的基本思想。_万字长文:特征可视化技术(CAM)...
  10. 如何确认guest账户是空密码_Mac OS X如何访问Windows局域网文件共享
  11. c语言中,x-y,'105',ab,7f8那个是正确的,C语言习题册
  12. mess组网 中继_Mesh路由和无线中继的差距在哪里?谁才是更好的选择?
  13. 照片编辑工具 Affinity Photo for Mac 1.7.1
  14. Latex系列(三)---IEEE Tran模板介绍
  15. 追本溯源,回归根本:第一届区块链技术及应用峰会(BTA)·中国“区块链核心技术”分论坛预告大放送...
  16. java之集合ArrayList,LinkedList,HashMap运用
  17. java提取图片base64,如何把
  18. 现如今社群乱象,社群玩法正解
  19. 人人都是产品经理总结 第五章
  20. 这本武林秘籍赶快收好

热门文章

  1. 10月3日 c语言 输入4*5矩阵
  2. 三下乡辅导孩子计算机知识,【“三下乡”社会实践活动】计算机学院——每个课程,都是你我成长的故事...
  3. c语言遍历json数组,如何使用c动态获取所有json元素?
  4. pomelo + vscode + typescript搭建可约束可调试的游戏服务端框架
  5. 常用自动门感应器工作原理
  6. 《第四期(2021-2022)传统行业云原生技术落地调研报告——金融篇》正式发布
  7. 【PyTorch系例】torch.Tensor详解和常用操作
  8. python-requests请求超时解决方案
  9. 发布WebGL遇到的问题
  10. 鸿蒙电脑系统运行exe,鸿蒙传说电脑版_电脑版鸿蒙传说下载「含模拟器」-华军软件园...