Editorial for Kế hoạch phát triển
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Lưu ý: Các code mẫu dưới đây chỉ mang tính tham khảo và có thể không AC được bài tập này
Code mẫu của flashmt
#include<iostream> #include<algorithm> #define fr(a,b,c) for (a=b;a<=c;a++) #define frr(a,b,c) for (a=b;a>=c;a--) using namespace std; int n,n0,n1,a[10][10],d[10],e[30],f[30],g[30],h[30],s; long long re,r[30],k; void att(int z) { int i,j,u=0,v,x=e[z],y=f[z],t[10]; if (z>n1) { fr(i,1,n1) if (d[e[i]]!=d[f[i]]) return; re+=r[s]; return; } att(z+1); fr(i,1,n0) { u=g[i]; v=h[i]; if ((d[u]==d[x] || d[u]==d[y]) && (d[v]==d[x] || d[v]==d[y])) return; } fr(i,1,n) t[i]=d[i]; j=d[y]; fr(i,1,n) if (d[i]==j) d[i]=d[x]; s++; att(z+1); s--; fr(i,1,n) d[i]=t[i]; } int main() { int i,j; cin >> n; fr(i,1,n) fr(j,1,n) { cin >> a[i][j]; if (i>=j) continue; if (a[i][j]) { e[++n1]=i; f[n1]=j; } else { g[++n0]=i; h[n0]=j; } } fr(i,1,n) d[i]=i; r[0]=1; fr(i,1,n1) r[i]=r[i-1]*3; att(1); cout << re << endl; return 0; }
Code mẫu của RR
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <cmath> #include <algorithm> #include <vector> #include <set> #include <map> #include <stack> #include <queue> #include <string> #include <deque> #include <complex> #define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++) #define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--) #define REP(i,a) for(int i=0,_a=(a); i<_a; i++) #define ll long long #define F first #define S second #define PB push_back #define MP make_pair using namespace std; const double PI = acos(-1.0); ll p3[50], res; int a[10][10], c[10][10]; void update(int n) { FOR(i,1,n) FOR(j,1,n) c[i][j] = a[i][j]; FOR(i,1,n) c[i][i] = 1; FOR(k,1,n) FOR(i,1,n) FOR(j,1,n) if (c[i][k] && c[k][j]) c[i][j] = 1; FOR(i,1,n) FOR(j,1,n) if (!c[i][j]) return ; int cnt = 0; FOR(i,1,n) FOR(j,i+1,n) cnt += a[i][j]; res += p3[cnt]; } void attempt(int i, int j, int n) { if (i > n) { update(n); return ; } if (i >= j) { attempt(i, j+1, n); return ; } if (j > n) { attempt(i+1, 1, n); return ; } FOR(now,0,1) { a[i][j] = a[j][i] = now; attempt(i, j+1, n); a[i][j] = a[j][i] = 0; } } int mark[10], dd[10], cnt; ll save[8] = {0,1,3,54,3834,1027080,1067308488LL,4390480193904LL}; void dfs(int u) { dd[u] = 1; cnt++; FOR(v,1,7) if (a[u][v] && !dd[v]) dfs(v); } int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); /* p3[0] = 1; FOR(i,1,25) p3[i] = p3[i-1] * 3; FOR(n,1,7) { res = 0; attempt(1,1,n); cout << res << endl; } */ int n; cin >> n; FOR(i,1,n) FOR(j,1,n) { cin >> a[i][j]; if (a[i][j]) mark[i] = mark[j] = 1; } ll res = 1; FOR(i,1,n) if (mark[i]) { cnt = 0; dfs(i); res = res * save[cnt]; } cout << res; return 0; }
Code mẫu của hieult
#include <cstdio> #include <iostream> //#include <conio.h> #include <stdlib.h> #include <algorithm> typedef long long ll; int d,flag[9],a[9][9],n; void duyet(int x) { d++; flag[x] = 1; for(int i = 1;i<=n;i++) if(!flag[i] && a[x][i]) duyet(i); } int main() { long long f[10]; f[1]=1; f[2]=3; f[3]=54; f[4]=3834; f[5]=1027080; f[6]=1067308488; long long u = 4390480; long long v = 193904; f[7] = u*1000000+v; long long KQ = 1; memset(flag,0,sizeof(flag)); scanf("%d",&n); for(int i = 1;i<=n;i++) for(int j = 1;j<=n;j++) scanf("%d",&a[i][j]); for(int i = 1;i<=n;i++) { d = 0; if(!flag[i]) { duyet(i); KQ = KQ*f[d]; } } printf("%lld",KQ); //getch(); }
Comments