#include <iostream>
#include <string>
using namespace std;
class ColorfulRoad{
#define INF 5000
public:
int getMin(string road){
int count=road.length();
int D[count];
for(int i=1;i<count;i++)D[i]=INF;
D[0]=0;
for(int i=1;i<count;i++){
for(int j=0;j<i;j++){
if(road[j]=='R' && road[i]=='G') D[i]=min(D[j]+(i-j)*(i-j),D[i]);
if(road[j]=='G' && road[i]=='B') D[i]=min(D[j]+(i-j)*(i-j),D[i]);
if(road[j]=='B' && road[i]=='R') D[i]=min(D[j]+(i-j)*(i-j),D[i]);
}
}
if(D[count-1]==INF)
return -1;
else
return D[count-1];
}
};
#include <string>
using namespace std;
class ColorfulRoad{
#define INF 5000
public:
int getMin(string road){
int count=road.length();
int D[count];
for(int i=1;i<count;i++)D[i]=INF;
D[0]=0;
for(int i=1;i<count;i++){
for(int j=0;j<i;j++){
if(road[j]=='R' && road[i]=='G') D[i]=min(D[j]+(i-j)*(i-j),D[i]);
if(road[j]=='G' && road[i]=='B') D[i]=min(D[j]+(i-j)*(i-j),D[i]);
if(road[j]=='B' && road[i]=='R') D[i]=min(D[j]+(i-j)*(i-j),D[i]);
}
}
if(D[count-1]==INF)
return -1;
else
return D[count-1];
}
};
作者:doom_ood 发表于2013-12-2 3:35:01 原文链接
阅读:89 评论:0 查看评论