牛客网Drop Voicing

题目描述:

Inaka composes music. Today's arrangement includes a chord of nnn notes that are pairwise distinct, represented by a permutation p1…np_{1 \dots n}p1n of integers from 111 to nnn (inclusive) denoting the notes from the lowest to the highest.

Her friend, Miyako, sneaks in and plays a trick by altering the chord with the following two operations:

  • Drop-2: Take out the second highest note and move it to the lowest position, i.e. change the permutation to pn−1,p1,p2,…,pn−3,pn−2,pnp_{n-1}, p_1, p_2, \dots, p_{n-3}, p_{n-2}, p_npn1,p1,p2,,pn3,pn2,pn.
  • Invert: Take out the lowest note and move it to the highest position, i.e. change the permutation to p2,p3,…,pn−1,pn,p1p_2, p_3, \dots, p_{n-1}, p_n, p_1p2,p3,,pn1,pn,p1.

Any number of consecutive Drop-2 operations is considered a multi-drop. Miyako would like to change the permutation to an ordered permutation, 1,2,…,n1, 2, \dots, n1,2,,n, in the fewest number of multi-drops possible. Please help her find the number of multi-drops needed.

输入描述:

输出描述:

列式1:

扫描二维码关注公众号,回复: 11440033 查看本文章

列式2:

:题面翻译自行解决

  这题我们将模型转换成有一个圆盘,圆盘上有n个位置,且有一个指针(初始时指针指向原 来的最后一个元素) 

  • 连续若干次操作1等价为改变指针指向的数所处的位置连续若干次操作
  • 连续若干次操作2等价为改变指针的位置

  这样以后我们就可以得出答案是在这个环上取一个最长不下降子序列,在此之后调整其他数即可AC。

代码如下:

#include<bits/stdc++.h>
using namespace std;
int n,a[1007],dp[1007];
int main()
{
    int cnt=0;
    cin>>n;
    for (int i=1; i<=n; i++) scanf("%d",&a[i]);
    for (int k=1; k<=n; k++)
    {
        for (int i=1; i<=n; i++)
        {
            dp[i]=1;
            for (int j=1; j<=i; j++)
                if (a[i]>a[j]) dp[i]=max(dp[i],dp[j]+1);//求最长不下降子序列 
            cnt=max(dp[i],cnt);
        }
        int t=a[1];
        for(int i=1;i<n;i++) a[i]=a[i+1]; a[n]=t;//圈圈转一位 
    }
    cout<<n-cnt<<endl;
    return 0;//随手带上结束 
}

猜你喜欢

转载自www.cnblogs.com/WWWZZZQQQ/p/13378113.html