1 solutions
-
0
C++ :
#include <cstdlib> #include <cstdio> #include <iostream> using namespace std; int n,k,m,cs=0,dian[300],ran=500,a,b;bool xian[300][300]={0}; int scan(int s) { for(int i=1;i<=m;i++) { bool ok=1; for(int j=1;j<=s-1;j++) { if(xian[j][s]==1&&dian[j]==i) { ok=0;break; } } if(!ok) continue; dian[s]=i; if(s==n) cs++; else scan(s+1); dian[s]=ran; ran++; } } int main() { scanf("%d%d%d",&n,&k,&m); for(int i=1;i<=k;i++) { scanf("%d%d",&a,&b); xian[a][b]=1; xian[b][a]=1; } scan(1); printf("%d",cs); return 0; }
Pascal :
var s,r,x,y,i,n,k,m:longint;l,f:array[0..101] of longint;a:array[0..10001,1..2] of longint; procedure p1(x,y:longint); begin r:=r+1; a[r,1]:=y;a[r,2]:=f[x]; f[x]:=r; end; procedure try(x:longint); var i:longint;c:array[1..6] of longint; begin if x>n then s:=s+1 else begin for i:=1 to k do c[i]:=0; i:=f[x]; while i>0 do begin c[l[a[i,1]]]:=1; i:=a[i,2]; end; for i:=1 to k do if c[i]=0 then begin l[x]:=i; try(x+1); end; end; end; begin readln(n,m,k); for i:=1 to m do begin read(x,y); if x<y then p1(y,x) else p1(x,y); end; try(1); writeln(s); end.
- 1
Information
- ID
- 679
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By