subiekooc

liujunhao 2024-03-02 15:17:05 2024-04-09 19:43:53 11 返回题目

#include<bits/stdc++.h>

using namespace std;

int x,y,z,ans=1e9;

int mem[110][110];

void dfs(int a,int b,int step){

if(step>ans)return ;
if(a==z||b==z){
	ans=min(ans,step);
}
if(mem[a][b]!=-1&&mem[a][b]<=step)return ;
mem[a][b]=step;
dfs(0,b,step+1);
dfs(x,b,step+1);
dfs(a,0,step+1);
dfs(a,y,step+1);
int d=min(a,y-b);
dfs(a-d,b+d,step+1);
d=min(b,x-a);
dfs(a+d,b-d,step+1);

} int main(){

memset(mem,-1,sizeof(mem));
cin>>x>>y>>z;
dfs(0,0,0);
if(ans==1e9)cout<<"impossible";
else cout<<ans;
return 0;

}

{{ vote && vote.total.up }}