hdu 个人排位赛 Travel

Problem E Travel

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 130    Accepted Submission(s): 60

Problem Description
It is said Guilin's scenery is the best in the world. Now since the first Guangxi Province Collegiate Programming Contest is held in Guilin, Luras decided to travel around Guilin. She knows that there will be n nodes in the travel map. Luras will pick a shortest way to go from node 1 to node n. You are a city designer who could decide if there is a bi-directional edge with the length of 1 between every two nodes. And you hope to build the roads to make the shortest path from 1 to n to be as many as possible. Could you tell Luras how many shortest path could it be at most between node 1 and node n in your final city graph?

Input
The first line is an integer T which indicates the case number.
And as for each case,  there will be one lines
In the line, there is 1 integer n, which indicates the number of node.
It is guaranteed that——
T is about 100.
for 100% cases, 2 <= n <= 40.
 
Output
As for each case, you need to output a single line.
There should be one integer in the line which means the maximum shortest path could be between node 1 and node n.
 
Sample Input
6
2
3
4
5
6
7
Sample Output
1
1
2
3
4
6


【题解】

比赛的时候眼睁睁看着AC的人越来越多但是我题目读不懂orz

题意:在结点1-n之间任意建边,使得从结点1到结点n的最短路径的数量达到最大。

思路:等同于求(n-2)的最大拆分的整数的乘积。

【代码】

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int f[45],n,t;
    f[0]=1,f[1]=1;
    for(int i=2;i<40;i++)
    {
        int t=1,j=i;
        while(j>4)
        {
            t*=3;
            j-=3;
        }
        t*=j;
        f[i]=t;
    }
    scanf("%d",&t);
    while(t--)
    {
        cin>>n;
        cout<<f[n-2]<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41117236/article/details/81046403
今日推荐