WA on #3 #9 #12 #13求调

P1433 吃奶酪

打错了一个地方(dp声明处) ```cpp #include<bits/stdc++.h> using namespace std; const int N = 16; int n; double f[N][1 << (N - 1)], dis[N][N], ax[N], ay[N]; double dp(int now, bitset<N> cur){ int cur_ulong = cur.to_ulong(); int a = 0; for(int i = 0; i < n; ++i) if(cur[i]) ++a; /*/ for(int i = 1; i <= a; ++i) printf("-----------"); printf("dp(%d,", now); cout << cur; printf(")\n"); //*/ if(f[now][cur_ulong] != 0) return f[now][cur_ulong]; if(a == n) return f[now][cur_ulong] = 0; double ret = 1e9; for(int i = 1; i <= n; ++i){ if(cur[i - 1]) continue; cur[i - 1] = 1; ret = min(ret, dp(i, cur) + dis[i][now]); cur[i - 1] = 0; } /*/ printf("dp(%d,", now); cout << cur; printf(")=%.2lf\n", ret); //*/ return f[now][cur_ulong] = ret; } double qpow(double a, int b){ if(b == 1) return a; if(b & 1) return qpow(a, b - 1) * a; int tmp = qpow(a, b >> 1); return tmp * tmp; } int main(){ scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%lf%lf", &ax[i], &ay[i]); for(int i = 1; i <= n; ++i) for(int j = 0; j < i; ++j) dis[j][i] = dis[i][j] = sqrt(qpow(ax[i] - ax[j], 2) + qpow(ay[i] - ay[j], 2)); printf("%.2lf", dp(0, 0)); return 0; } ```
by sort_12470 @ 2024-02-22 11:05:57


@[sort_12470](/user/779309) 但是还是有错
by sort_12470 @ 2024-02-22 11:15:54


xdm发现问题了。 ret不能开1e9,不够用。 要开intmax。 此贴结。
by sort_12470 @ 2024-02-22 11:21:16


|