"Bc#24 1002 hdoj 5273" Dylans loves sequence

Source: Internet
Author: User

"Bc#24 1002 hdoj 5273" Dylans loves sequence

Reverse to the game when all kinds of wonderful poses are on the merger also suppressed out of who know to show me this .... After the game some ideas received after the game of inspiration Dp[l][r] is l~r between the reverse

First the violence to enumerate the dp[1][1~n] and I from the 2~n enumeration left boundary right boundary from I+1~n so dp[i][j] that the interval left endpoint from 2 back all the inverse logarithm

and Dp[i][j] that is dp[i-1][j] in the i-1 of the reverse logarithm minus the remainder such order of violence can be ... Still looking at the brain, tot.

The code is as follows

#include <cstdio>using namespace STD;intdp[1111][1111];intnum[1111];intcnt[1111];intMain () {intI,n,q,j,l,r;scanf("%d%d", &n,&q); for(i =1; I <= N; ++i)scanf("%d", &num[i]); dp[1][1] =0; for(i =2; I <= N; ++i) {dp[1][i] = dp[1][i-1]; for(j =1; J < I; ++J) {if(Num[j] > Num[i]) dp[1][i]++; }    } for(i =2; I < n; ++i) {cnt[i-1] = Num[i] < num[i-1]?1:0; for(j = i+1; J <= N; ++J) {if(num[i-1] > Num[j]) cnt[i-1]++; DP[I][J] = dp[i-1][J]-cnt[i-1]; }    } while(q--) {scanf("%d%d", &l,&r);printf("%d\n", Dp[l][r]); }return 0;}

"Bc#24 1002 hdoj 5273" Dylans loves sequence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.