记录编号 216636 评测结果 AAAAAAAAAA
题目名称 [IOI 1999] 花店橱窗 最终得分 100
用户昵称 Gravatarliu_runda 是否通过 通过
代码语言 C++ 运行时间 0.008 s
提交时间 2015-12-30 10:25:50 内存使用 0.34 MiB
显示代码纯文本
#include<cstdio>
#define maxn 102
using namespace std;
int w[maxn][maxn];
int ans[maxn][maxn];//first i flowers in first j vases ans[i][j]仅在i<=v有意义 
bool flag[maxn][maxn];//first i flowers in first j vases ,whether flower i in vase j
void output(int f,int v){
	if(f==1&&flag[f][v])printf("%d",v);
	else if(flag[f][v]){
		output(f-1,v-1);
		printf(" %d",v);
	}
	else output(f,v-1);
}
int main(){
	freopen("hana.in","r",stdin);
	freopen("hana.out","w",stdout);
	int f,v;
	scanf("%d %d",&f,&v);
	for(int i = 1;i<=f;++i)
		for(int j = 1;j<=v;++j){
			scanf("%d",&w[i][j]);//flower f in vase v
			w[i][j]+=50;
		}
	ans[1][1] = w[1][1];flag[1][1] = true;
	for(int i = 2;i<=v;++i){
		ans[1][i] = ans[1][i-1];
		if(w[1][i]>ans[1][i-1]){
			ans[1][i] = w[1][i];
			flag[1][i] = true;
		}
	}
	for(int i = 2;i<=v&&i<=f;++i)ans[i][i] = ans[i-1][i-1] + w[i][i];
	for(int i = 2;i<=f;++i){
		for(int j = i+1;j<=v;++j){
			ans[i][j] = ans[i][j-1];
			if(ans[i-1][j-1]+w[i][j]>ans[i][j]){
				ans[i][j]=ans[i-1][j-1]+w[i][j];
				flag[i][j] = true;
			}
		}
	}
	/*for(int i = 1;i<=f;++i){
		for(int j = i;j<=v;++j)printf("ans[%d][%d]==%d ",i,j,ans[i][j]);
		printf("\n");
	}*/
	printf("%d\n",ans[f][v]-50*f);
	output(f,v);
	fclose(stdin);fclose(stdout);				
	return 0;
}