暴力解法本地最大数据花了1min+,不抱希望地提交上去居然也过了??
查看原帖
暴力解法本地最大数据花了1min+,不抱希望地提交上去居然也过了??
319478
zhibuba楼主2020/6/12 09:33
#include <stdio.h>

int a, n, m, x, A[21], B[21];

int test(int t)
{
    for (int i = 1; i <= n - 1; i++)
    {
        if (i == 1)
            A[i] = B[i] = a;
        else if (i == 2)
            A[i] = a, B[i] = t;
        else
            A[i] = A[i - 1] + B[i - 2], B[i] = B[i - 1] + B[i - 2];
    }
    return A[n - 1];
}


int main(void)
{
    scanf("%d%d%d%d", &a, &n, &m, &x);
    for (int t = 0; test(t) != m; t++)
        ;
    printf("%d", A[x]);
}
2020/6/12 09:33
加载中...