新生赛暑假第一场 解题报告

未码出的题 C、D、E、F

超时的D、E

D题报告

D.Brackets 

This year MK is 5 years old. So he decides to learn some arithmetic. But he was confused by how to write the brackets. He has already known that the brackets should match when writing them correctly. Such as “()(())” is correct but “())(” is not.

The problem is that, if there are N pairs of brackets, how many ways that MK can write them correctly?           

Input 

   There are several test cases. Each case contains a number N (1 <= N <= 1000) indicating the pairs of brackets.

Output 

For each case, please output the answer mod 1,000,000,007.

Sample Input 

5

7

Sample Output 

42

429

代码

int n;
__64int f[maxn];
int main() {
    f[0] = 1;
    for(int i = 1; i <= 1000; i++) {
        for(int j = 0; j < i; j++) {
            f[i] += f[j] * f[i - j - 1] %1,000,000,007;
            f[i] %=1,000,000,007;
        }
    }
    while(scanf("%d", &n) == 1) {
        printf("%I64d\n", f[n]);
    }
    return 0;
}
原代码超时原因一、使用暴力法 二、每一处都mod所以大数越界;

总结:看要求超过100,000,000以上输入输出直接用c语言;测试数据为大数__int 64,还有用公式找关系。

公式为卡塔兰数


E题报告

E.Function

Define a function f(n)=(f(n-1)+1)/f(n-2). You already got f(1) and f(2). Now, give you a number m, please find the value of f(m).

Input

There are several test cases. Each case contains three integers indicating f(1), f(2) and m ( 1 <= f(1), f(2), m <= 1000,000,000).

Output

For each case, please output the value of f(m), rounded to 6 decimal places.

Sample Input

1 1 3

Sample Output

2000000


代码:

int main()
{
	double f[5];
	long a,b,m;
	while(scanf("%ld %ld %ld",&a,&b,&m)!=EOF)
	{
		f[0]=a;
		f[1]=b;
		for(int i=2;i<5;i++)
		{
			f[i]=((f[i-1]+1)/f[i-2]);
		}
		printf("%.4lf\n",f[(m-1)%5]);
	}
	return 0;
}



总结:

原因基本与D的一样


最后总结:

加强算法了解和拓宽知识面,多熟悉复杂问题的分析。


7/7/2013 9:15 PM 第一次完稿。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值