HDU 1703 PBD 递推

来源:互联网 发布:angular.js 编辑:程序博客网 时间:2024/05/20 15:11

这一题推了半天也没有推出来,推的时候各种复杂啊!感觉自己弱暴了没,思考问题的方法不行!现在看了别人的报告只能说是想通了。当n大于等于5的思路大致是这样的:(PS递归的问题,总是要基于前一个状态的,所以一般从前一个状态分析起)。假如有ABCD四个人,他们完成信息交流需要f次,那末,五个人的时候,比如添加了E,可以首先让E与A进行一次信息交流,这时他们的信息互换,可以看作E和A为一个人,而E的信息也随A传递,那么这时仍然经过f次,ABCD四个人的信息交流完毕,而且信息中也都含有E的信息。此时,ABCD四个人已经都掌握其他所有人的信息,只剩下E,再让E与他们任何一一个人一次信息交流即可。所以:f[n]=f[n-1]+2


Description

PrisonBreak is a popular TV programme in HDU. ACboy likes it very much, and he join a PrisonBreak discussing team called "PBD".Every Tuesday night, a lot of PBDers will contact with each other to discuss the newest plot of PrisonBreak season2. Generally speaking, every PBDer has distinct ideas about the play, so everyone want to know all the others' ideas. For example, when ACboy contract with Sam, ACboy will tell all the ideas he konws to Sam, and Sam will also tell all the ideas he konws to ACboy, and the call costs 5 yuan. 
If there are N people in the "PBD" team, what is the minimum cost to let everyone knows all the others' ideas?
 

Input

The input contains multiple test cases.
Each test case contains a number N, means there are N people in the "PBD" team.N = 0 ends the input.(A call cost 5 yuan).
 

Output

for each case, output a integer represent the minimum cost to let everyone knows all the others' ideas.
 

Sample Input

12340
 

Sample Output

051520

Hint

If there are 2 people, for example, named A, B. Then A calls B, then A and B will know each other's ideas, so it only needs one call, so the minimum cost is 1*5 = 5 yuan. 
 

#include<cstdio>#include<iostream>#include<algorithm>using namespace std;int main(){   int f[20000];   f[1]=0;   f[2]=1;   f[3]=3;   f[4]=4;   for(int i=5;i<=10000;i++)    f[i]=f[i-1]+2;    int n;    while(scanf("%d",&n)&&n)    {        printf("%d\n",f[n]*5);    }    return 0;}


0 0
原创粉丝点击