| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
还是写成循环吧……In Reply To:还是不行 >.< Posted by:cuiaoxiang at 2007-10-12 13:09:19 > Source
>
> Problem: 3056 User: cuiaoxiang
> Memory: N/A Time: N/A
> Language: G++ Result: Time Limit Exceeded
>
> Source
> #include <iostream>
>
> using namespace std;
>
> const int N = 1000 + 10;
> int dp[N][N];
> int a[N];
>
> int run(int s, int t)
> {
> if (dp[s][t] != -1) return dp[s][t];
> int &ret = dp[s][t];
> int i;
> ret = 0;
> for (i = s + 1; i < t; i += 2)
> ret = max(ret, run(s + 1, i) + run(i + 1, t) + (a[s] == a[i] ? 1 : 0));
> return ret;
> }
>
> int main()
> {
> int casenum, i, n;
> scanf("%d", &casenum);
> while (casenum--)
> {
> scanf("%d", &n);
> for (i = 0; i < n; ++i) scanf("%d", a + i);
> memset(dp, 255, sizeof(dp));
> printf("%d\n", run(0, n));
> }
> return 0;
> }
>
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator