ZOJ Monthly, August 2011 zoj 3523

20 篇文章 0 订阅
#include<iostream>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<string>
#include<string.h>
using namespace std;
 
#define pi acos(-1.0)
#define LL long long
#define inf 0x7fffffff
#define eps 1e-8
#define E exp(1.0)
template<typename T>  T Gmax(T a,T b){return a>b?a:b;}
template<typename T>  T Gmin(T a,T b){return a<b?a:b;}
const int N=0;

struct node
{
	char s[51];
	int id;
}str[51];

bool cmp(node a,node b)
{
	if(strcmp(a.s,b.s)<0)
		return true;
	if(strcmp(a.s,b.s)==0)
		return a.id<b.id;
	return false;
}


int main()
{
	int n,m,i,j,k;
	int dp[51];
	while(scanf("%d%d",&n,&m)!=-1)
	{
		getchar();
		int sum=0,Max;
		for(i=1;i<=n;i++)
		{
			
			for(j=0;j<m;j++)
			{
				gets(str[j].s);
				str[j].id=j;
			}
			sort(str,str+m,cmp);
	//		for(k=0;k<m;k++)
	//			cout<<str[k].s<<" "<<str[k].id<<endl;
			for(k=0;k<m;k++)
				dp[k]=1;
			Max=1;
			for(k=1;k<m;k++)
			{
	//			cout<<"1"<<endl;
				for(j=0;j<k;j++)
				{
					if(str[j].id<str[k].id)
					{
						if(dp[j]+1>dp[k])
							dp[k]=dp[j]+1;
					}
				}
				if(dp[k]>Max)
					Max=dp[k];
			}
	//		cout<<max<<endl;
			sum+=(m-Max);
		}
		printf("%d\n",sum);
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值