强行全排列,9秒,11!的复杂度,稳妥超时:
代码:
#include <stdio.h> #include <memory.h> #include <math.h> #include <string> #include <string.h> #include <vector> #include <set> #include <stack> #include <queue> #include <algorithm> #include <map> #define I scanf #define OL puts #define O printf #define F(a,b,c) for(a=b;a<c;a++) #define FF(a,b) for(a=0;a<b;a++) #define FG(a,b) for(a=b-1;a>=0;a--) #define LEN 3000 #define MAX 0x06FFFFFF #define V vector<int> using namespace std; int main(){ // freopen("D:/CbWorkspace/blue_bridge/带分数.txt","r",stdin); int eq=100; // I("%d",&eq); string problem="+/123456789"; do{ int p=problem.find(‘+‘); int d=problem.find(‘/‘); if(abs(p-d)==1) continue; if(p==0 || d==0 || p==10 || d==10) continue; if(d<p) continue; int a,b,c; sscanf(problem.substr(p+1,d-p-1).c_str(),"%d",&b); sscanf(problem.substr(d+1,10-d).c_str(),"%d",&c); if(b%c) continue; sscanf(problem.substr(0,p).c_str(),"%d",&a); if((a+b/c)==eq) puts(problem.c_str()); }while(next_permutation(problem.begin(),problem.end())); return 0; }