3
31
2015
0

Tyvj 1006 isbn

#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
	int c,a=0; string s="";
	for (int i=1;i<=9;++i)
	{
		c=getchar(); s+=c;
		if (c=='-') --i; //序号指数字的序号,连字符不算
		else if (c!='-')
			a=(a+(c-'0')*i)%11;
	}
	getchar(); c=getchar();
	if ((a==10 && c=='X') || a+'0'==c) { //读入特判
		cout<<"Right"; return 0;
	}
	cout<<s<<'-';
	if (a==10) cout<<'X'; //输出特判
	else cout<<a;
	return 0;
}
Category: 题解 | Tags: Tyvj 模拟
3
31
2015
0

Tyvj 1005 采药

 

#include <iostream>
using namespace std;
int t,m,f[1001],w[101],v[101];
int main()
{
	cin>>t>>m;
	for (int i=1;i<=m;++i)
		cin>>w[i]>>v[i];
	for (int i=1;i<=m;++i)
		for (int j=t;j>=w[i];--j)
			if (f[j]<f[j-w[i]]+v[i])
				f[j]=f[j-w[i]]+v[i];
	cout<<f[t];
	return 0;
}
Category: 题解 | Tags: Tyvj 动规
3
30
2015
0

Tyvj 1004 滑雪

#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int s[100][100],r,c,a[100][100],ans;

int f(int x,int y) { //从x,y开始最长走几步
	if (s[x][y]!=-1) return s[x][y]; //如果算过就直接返回
	s[x][y]=1;
	if (x>0 && a[x][y]>a[x-1][y])
		s[x][y]=max(s[x][y],f(x-1,y)+1);
	if (y>0 && a[x][y]>a[x][y-1])
		s[x][y]=max(s[x][y],f(x,y-1)+1);
	if (x<r-1 && a[x][y]>a[x+1][y])
		s[x][y]=max(s[x][y],f(x+1,y)+1);
	if (y<c-1 && a[x][y]>a[x][y+1])
		s[x][y]=max(s[x][y],f(x,y+1)+1);
	return s[x][y];
}

int main() {
	cin>>r>>c; memset(s,-1,sizeof(s));
	for (int i=0;i<r;++i)
		for (int j=0;j<c;++j)
			cin>>a[i][j];
	for (int i=0;i<r;++i)
		for (int j=0;j<c;++j)
			ans=max(ans,f(i,j)); //求最大值
	cout<<ans;
	return 0;
}
Category: 题解 | Tags: Tyvj 记忆化搜索

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com