All pastes #1718790 Raw Edit

Stuff

public cpp v1 · immutable
#1718790 ·published 2009-12-17 22:25 UTC
rendered paste body
#include <iostream>#include <vector>using namespace std;int wyn[52][52];int f(int cuts[52],int i,int j){	if(wyn[i][j]!=1000000) return wyn[i][j];		else	{				int min=wyn[i][j];		int tmp;			for(int x=i+1;x<j;x++)		{			tmp=f(cuts,i,x)+f(cuts,x,j)+cuts[j]-cuts[i];			if(min>tmp)min=tmp;								}		wyn[i][j]=min;				return min;	}}		int main(){  int n; scanf("%d",&n);	while(n!=0)	{		int k;		cin>>k;		int cuts[52];		cuts[0]=0;		for(int i=1;i<=k;i++)scanf("%d",&cuts[i]);		cuts[k+1]=n;				for(int i=0;i<=k+1;i++)		{			for(int j=0;j<=k+1;j++)wyn[i][j]=1000000;		}		for(int i=0;i<=k;i++)wyn[i][i+1]=0;				cout<<"The minimum cutting is "<<f(cuts,0,k+1)<<"."<<endl;		scanf("%d",&n);}}