锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
鏁版嵁閲忔瘮杈冨皯錛岀敤鍥炴函娉曪紝dp涔熻銆?br />
#include聽<fstream>
using聽namespace聽std;
ifstream聽fin("rockers.in");
ofstream聽fout("rockers.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
int聽capacity[20];;
int聽songs[20];
int聽song_num,disk_num;
int聽res聽=聽0;
int聽cur;
void聽backtracing(int聽depth,int聽last)
{
聽聽聽聽if(depth==song_num){
聽聽聽聽聽聽聽聽if(cur>res){
聽聽聽聽聽聽聽聽聽聽聽聽res聽=聽cur;
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽return;
聽聽聽聽}
聽聽聽
聽聽聽 //濡傛灉鍚庨潰鎵鏈夌殑姝屾洸閮藉姞涓婅繕姣旀渶浼樺煎皬錛屽壀鏋?br />聽聽聽聽if(cur+song_num-depth<=res)
聽聽聽聽聽聽聽return;聽
聽聽聽聽for(int聽i=last;i<disk_num;++i){
聽聽聽聽聽聽聽聽 //濡傛灉褰撳墠姝屾洸闇瑕佸埢褰曪紝閭e彧闇鍒誨湪絎竴寮犺兘瑁呭緱涓嬬殑鍏夌洏涓娿?br />聽聽聽聽聽聽聽聽if(聽capacity[i]>=songs[depth]){
聽聽聽聽聽聽聽聽聽聽聽聽cur++;
聽聽聽聽聽聽聽聽聽聽聽聽capacity[i]-=songs[depth];
聽聽聽聽聽聽聽聽聽聽聽聽backtracing(depth+1,i);
聽聽聽聽聽聽聽聽聽聽聽聽capacity[i]+=songs[depth];
聽聽聽聽聽聽聽聽聽聽聽聽cur--;
聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽 // 涓嶅埢褰撳墠姝屾洸
聽聽聽聽backtracing(depth+1,last);
}
void聽solve()
{
聽聽聽聽int聽c;
聽聽聽聽in>>song_num>>c>>disk_num;
聽聽聽聽for(int聽i=0;i<song_num;++i)
聽聽聽聽聽聽聽聽in>>songs[i];
聽聽聽聽for(int聽i=0;i<disk_num;++i)
聽聽聽聽聽聽聽聽capacity[i]聽=聽c;
聽聽聽聽backtracing(0,0);
聽聽聽聽out<<res<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
#include聽<fstream>
#include聽<set>
#include聽<queue>
using聽namespace聽std;
ifstream聽fin("msquare.in");
ofstream聽fout("msquare.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
int聽final[8];
set<int>visited;
char聽result[8*7*6*5*4*3*2*1+1];
struct聽queue_node{
聽聽聽聽int聽current[8];
聽聽聽聽queue_node聽*parent;
聽聽聽聽char聽op;
};
void聽op(int聽*current,char聽c)
{
聽聽聽聽int聽tmp;
聽聽聽聽switch(c){
聽聽聽聽聽聽聽聽case聽'A':
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽i=0;i<4;++i)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽swap(current[i],current[7-i]);
聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽case聽'B':
聽聽聽聽聽聽聽聽聽聽聽聽tmp聽=聽current[3];
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽i=3;i>=1;--i)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽current[i]聽=聽current[i-1];
聽聽聽聽聽聽聽聽聽聽聽聽current[0]聽=聽tmp;
聽聽聽聽聽聽聽聽聽聽聽聽tmp聽=聽current[4];
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽i=4;i<=6;++i)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽current[i]聽=聽current[i+1];
聽聽聽聽聽聽聽聽聽聽聽聽current[7]聽=聽tmp;
聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽case聽'C':
聽聽聽聽聽聽聽聽聽聽聽聽tmp聽=聽current[6];
聽聽聽聽聽聽聽聽聽聽聽聽current[6]聽=聽current[5];
聽聽聽聽聽聽聽聽聽聽聽聽current[5]聽=聽current[2];
聽聽聽聽聽聽聽聽聽聽聽聽current[2]聽=聽current[1];
聽聽聽聽聽聽聽聽聽聽聽聽current[1]聽=聽tmp;
聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽}
}
int聽cur_value(int聽*cur)
{
聽聽聽聽int聽res聽=聽0;
聽聽聽聽for(int聽i=0;i<8;++i){
聽聽聽聽聽聽聽聽res*=10;
聽聽聽聽聽聽聽聽res+=cur[i];
聽聽聽聽}
聽聽聽聽return聽res;
}
void聽solve()
{
聽聽聽聽for(int聽i=0;i<8;++i){
聽聽聽聽聽聽聽聽in>>final[i];
聽聽聽聽}
聽聽聽聽queue<queue_node*>聽q;
聽聽聽聽queue_node聽*node聽=聽new聽queue_node;
聽聽聽聽for(int聽i=0;i<8;++i)
聽聽聽聽聽聽聽聽node->current[i]聽=聽i+1;
聽聽聽聽node->parent聽=聽NULL;
聽聽聽聽q.push(node);
聽聽聽聽while(聽!q.empty()聽){
聽聽聽聽聽聽聽聽queue_node聽*node聽=聽q.front();
聽聽聽聽聽聽聽聽q.pop();
聽聽聽聽聽聽聽聽int聽cur聽=聽cur_value(node->current);
聽聽聽聽聽聽聽聽if(聽visited.find(聽cur)聽!=聽visited.end())
聽聽聽聽聽聽聽聽聽聽聽聽continue;
聽聽聽聽聽聽聽聽visited.insert(cur);
聽聽聽聽聽聽聽聽bool聽ok聽=聽true;
聽聽聽聽聽聽聽聽for(int聽i=0;i<8;++i){
聽聽聽聽聽聽聽聽聽聽聽聽if(node->current[i]!=final[i]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽ok聽=聽false;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽break;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽if(ok){
聽聽聽聽聽聽聽聽聽聽聽聽int聽i聽=聽0;
聽聽聽聽聽聽聽聽聽聽聽聽while(node->parent!=NULL){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽result[i++]聽=聽node->op;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽node=node->parent;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽if(i==0){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽out<<0<<endl<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit(0);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽out<<i<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽int聽j;
聽聽聽聽聽聽聽聽聽聽聽聽i--;
聽聽聽聽聽聽聽聽聽聽聽聽for(j=0;i>=0;i--,j++){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽out<<result[i];
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(j%60==59)聽out<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽if(j%60!=0)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽out<<endl;
聽聽聽聽聽聽聽聽聽聽聽聽exit(0);
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽for(char聽c='A';c<='C';++c){
聽聽聽聽聽聽聽聽聽聽聽聽queue_node聽*聽n聽=聽new聽queue_node;
聽聽聽聽聽聽聽聽聽聽聽聽memcpy(n->current,node->current,sizeof(node->current));
聽聽聽聽聽聽聽聽聽聽聽聽op(n->current,c);
聽聽聽聽聽聽聽聽聽聽聽聽n->op聽=聽c;
聽聽聽聽聽聽聽聽聽聽聽聽n->parent聽=聽node;
聽聽聽聽聽聽聽聽聽聽聽聽q.push(n);
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
棣栧厛鐢?floyd璁$畻鍑轟袱涓や箣闂寸殑鏈鐭礬寰勩傜劧鍚庣敤dfs灝嗗浘鐫鑹層傚姣忎袱涓や笉鍚岄鑹茬殑緇撶偣錛屾垜浠妸瀹冧滑鐩歌繛錛岀劧鍚庣湅浜х敓鐨勫浘鐨勭洿寰勭殑澶у皬銆?br />鐩村緞鐨勫ぇ灝忓彧鍙兘浠嶄負鍘熶袱榪為氬浘鐩村緞涔嬩竴錛屾垨鑰呮槸鍖呮嫭鏂版坊鍔犵殑璺緞鎵浜х敓鐨勬渶闀胯礬寰勶紝鍙栬繖涓夎呬腑鐨勬渶澶у箋傛柊璺緞浜х敓鐨勬渶闀胯礬寰勫彧鍙兘鏄袱鐐圭殑璺濈鍔犱笂涓ょ偣鍒板叾浠栫偣鐨勬渶闀胯窛紱匯傛渶寮濮嬬殑鏃跺欏彧鑰冭檻浜嗘柊娣誨姞鐨勮礬寰勶紝娌¤冭檻鍘熺洿寰勪細姣旀柊璺緞澶х殑鎯呭喌錛寃a浜唍嬈°傘?br />
#include聽<fstream>
#include聽<cfloat>
#include聽<cmath>
using聽namespace聽std;
ifstream聽fin("cowtour.in");
ofstream聽fout("cowtour.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
double聽path[150][150];
char聽graph[150][150];
int聽x[150];
int聽y[150];
int聽n;
int聽color[150];
double聽diameter[150];
double聽maxPath[150];
void聽floyd()
{
聽聽聽聽for(int聽k=0;k<n;++k)
聽聽聽聽聽聽聽聽for(int聽i=0;i<n;++i)
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽j=0;j<n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i!=j){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽path[i][j]=min(path[i][j],path[i][k]+path[k][j]);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
}
void聽make_color(int聽i,int聽c)
{
聽聽聽聽if(聽color[i]!=0聽)
聽聽聽聽聽聽聽聽return;
聽聽聽聽color[i]聽=聽c;
聽聽聽聽for(int聽j=0;j<n;++j){
聽聽聽聽聽聽聽聽if(color[j]==0&&graph[i][j])
聽聽聽聽聽聽聽聽聽聽聽聽make_color(j,c);
聽聽聽聽}
}
void聽solve()
{
聽聽聽聽in>>n;
聽聽聽聽for(int聽i=0;i<n;++i){
聽聽聽聽聽聽聽聽in>>x[i]>>y[i];
聽聽聽聽}
聽聽聽聽for(int聽i=0;i<n;++i){
聽聽聽聽聽聽聽聽string聽s;
聽聽聽聽聽聽聽聽in>>s;
聽聽聽聽聽聽聽聽for(int聽j=0;j<n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽graph[i][j]=s[j]-'0';
聽聽聽聽聽聽聽聽聽聽聽聽if(graph[i][j]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽path[i][j]聽=聽sqrt(聽(x[i]-x[j])*(x[i]-x[j])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽+(y[i]-y[j])*(y[i]-y[j])聽);
聽聽聽聽聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽path[i][j]聽=聽DBL_MAX/4;
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽}
聽聽聽聽floyd();
聽聽聽聽int聽c聽=聽0;
聽聽聽聽for(int聽i=0;i<n;++i)
聽聽聽聽聽聽聽聽if(color[i]==0)
聽聽聽聽聽聽聽聽聽聽聽聽make_color(i,++c);
聽聽聽聽for(int聽i=0;i<n;++i){
聽聽聽聽聽聽聽聽maxPath[i]聽=聽0;
聽聽聽聽聽聽聽聽for(int聽j=0;j<n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽if(i!=j&&color[i]==color[j]){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽maxPath[i]聽=聽max(maxPath[i],path[i][j]);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽diameter[color[i]]聽=聽max(diameter[color[i]],maxPath[i]);
聽聽聽聽}
聽聽聽聽double聽dia聽=聽DBL_MAX;
聽聽聽聽for(int聽i=0;i<n;++i)
聽聽聽聽聽聽聽聽for(int聽j=i+1;j<n;++j){
聽聽聽聽聽聽聽聽聽聽聽聽if(color[i]==color[j])聽continue;
聽聽聽聽聽聽聽聽聽聽聽聽double聽d1聽=聽0;
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽p=0;p<n;++p){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i!=p&&color[i]==color[p])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽d1聽=聽max(d1,path[i][p]);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽double聽d2聽=聽0;
聽聽聽聽聽聽聽聽聽聽聽聽for(int聽p=0;p<n;++p){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(j!=p&&color[j]==color[p])
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽d2聽=聽max(d2,path[j][p]);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽double聽dist聽=聽sqrt(聽(x[i]-x[j])*(x[i]-x[j])+
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽(y[i]-y[j])*(y[i]-y[j])聽);
聽聽聽聽聽聽聽聽聽聽聽聽dia聽=聽min(dia,max(d1+d2+dist,max(diameter[color[i]],diameter[color[j]]))聽);
聽聽聽聽聽聽聽聽}
聽聽聽聽out.setf(ios::fixed,ios::floatfield);
聽聽聽聽out.precision(6);
聽聽聽聽out<<dia<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>
#include聽<fstream>
#include聽<queue>
using聽namespace聽std;
ifstream聽fin("maze1.in");
ofstream聽fout("maze1.out");
#ifdef聽_DEBUG
#define聽out聽cout
#define聽in聽cin
#else
#define聽out聽fout
#define聽in聽fin
#endif
char聽maze[2*100+1][2*38+1];
bool聽visited[100][38];
int聽shortest1[100][38];
int聽shortest2[100][38];
bool聽get_first;
int聽exit1r,exit1c;
int聽exit2r,exit2c;
int聽w,h;
struct聽queue_node{
聽聽聽聽int聽i,j,depth;
聽聽聽聽queue_node(int聽i,int聽j,int聽depth){
聽聽聽聽聽聽聽聽this->i聽=聽i;
聽聽聽聽聽聽聽聽this->j聽=聽j;
聽聽聽聽聽聽聽聽this->depth聽=聽depth;
聽聽聽聽}
};
void聽bfs(int聽i,int聽j,int聽shortest[100][38])
{
聽聽聽聽queue<queue_node>q;
聽聽聽聽q.push(queue_node(i,j,1));
聽聽聽聽while(!q.empty()){
聽聽聽聽聽聽聽聽queue_node聽node聽=聽q.front();
聽聽聽聽聽聽聽聽q.pop();
聽聽聽聽聽聽聽聽if(visited[node.i][node.j])
聽聽聽聽聽聽聽聽聽聽聽聽continue;
聽聽聽聽聽聽聽聽visited[node.i][node.j]聽=聽true;
聽聽聽聽聽聽聽聽shortest[node.i][node.j]聽=聽node.depth;
聽聽聽聽聽聽聽聽if(node.i!=0&&maze[2*node.i][2*node.j+1]=='聽'){
聽聽聽聽聽聽聽聽聽聽聽聽q.push(queue_node(node.i-1,node.j,node.depth+1));
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽if(node.i!=h-1&&maze[2*node.i+2][2*node.j+1]=='聽'){
聽聽聽聽聽聽聽聽聽聽聽聽q.push(queue_node(node.i+1,node.j,node.depth+1));
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽if(node.j!=0&&maze[2*node.i+1][2*node.j]=='聽'){
聽聽聽聽聽聽聽聽聽聽聽聽q.push(queue_node(node.i,node.j-1,node.depth+1));
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽if(node.j!=w-1&&maze[2*node.i+1][2*node.j+2]=='聽'){
聽聽聽聽聽聽聽聽聽聽聽聽q.push(queue_node(node.i,node.j+1,node.depth+1));
聽聽聽聽聽聽聽聽}
聽聽聽聽}
}
void聽solve()
{
聽聽聽聽in>>w>>h;
聽聽聽聽for(int聽i=0;i<2*h+1;++i)
聽聽聽聽聽聽聽聽for(int聽j=0;j<2*w+1;++j){
聽聽聽聽聽聽聽聽聽聽聽聽do{
聽聽聽聽聽聽聽聽聽聽聽聽in.get(maze[i][j]);
聽聽聽聽聽聽聽聽聽聽聽聽}while(maze[i][j]=='\n');
聽聽聽聽聽聽聽聽聽聽聽聽if((i==0||i==2*h||j==0||j==2*w)&&maze[i][j]=='聽'){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(!get_first){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i==2*h)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit1r聽=聽h-1;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽else
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit1r聽=聽i/2;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(j==2*w)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit1c聽=聽w-1;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽else
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit1c聽=聽j/2;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽get_first聽=聽true;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(i==2*h)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit2r聽=聽h-1;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽else
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit2r聽=聽i/2;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(j==2*w)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit2c聽=聽w-1;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽else
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽exit2c聽=聽j/2;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽memset(visited,0,sizeof(visited));
聽聽聽聽bfs(exit1r,exit1c,shortest1);
聽聽聽聽memset(visited,0,sizeof(visited));
聽聽聽聽bfs(exit2r,exit2c,shortest2);
聽聽聽聽int聽res聽=聽INT_MIN;
聽聽聽聽for(int聽i=0;i<h;++i)
聽聽聽聽聽for(int聽j=0;j<w;++j){
聽聽聽聽聽聽聽聽聽res聽=聽max(res,聽min(shortest1[i][j],shortest2[i][j])聽);
聽聽聽聽聽}
聽聽聽聽out<<res<<endl;
}
int聽main(int聽argc,char聽*argv[])
{
聽聽聽聽solve();聽
聽聽聽聽return聽0;
}
]]>