HDU2563

1.题目链接。这个应该叫做回溯的裸题,感受一下dfs过程中是如何回溯的。但是这个程序的复杂度还是很高的,如果直接每次输入都dfs会TLE,所以我们把所有的数据全部打个表放到数组1里面。直接0ms就过了。打表的程序没了,嘿嘿,就直接给出AC的代码吧

#include<bits/stdc++.h>
using namespace std;
int a[21]={0,3,7,17,41,99,239,577,1393,3363,8119,19601,47321,114243,275807,665857,1607521,3880899,9369319,22619537,54608393};
int main()
{

    int T;
    scanf("%d",&T);
    int n;
    for(int i=0;i<T;i++)
    {
        scanf("%d",&n);
        printf("%d\n",a[n]);
    }
    return 0;

}

猜你喜欢

转载自blog.csdn.net/weixin_41863129/article/details/86564734
hdu