【DP】HDOJ 5045 Contest
2277 단어 HDU
#include <iostream>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <time.h>
#define maxn 1205
#define maxm 40005
//#define eps 1e-10
#define mod 10000007
#define INF 1e9
#define lowbit(x) (x&(-x))
#define mp make_pair
#define ls o<<1
#define rs o<<1 | 1
#define lson o<<1, L, mid
#define rson o<<1 | 1, mid+1, R
typedef long long LL;
typedef unsigned long long ULL;
//typedef int LL;
using namespace std;
LL qpow(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base;base=base*base;b/=2;}return res;}
LL powmod(LL a, LL b){LL res=1,base=a;while(b){if(b%2)res=res*base%mod;base=base*base%mod;b/=2;}return res;}
void scanf(int &__x){__x=0;char __ch=getchar();while(__ch==' '||__ch=='
')__ch=getchar();while(__ch>='0'&&__ch<='9')__x=__x*10+__ch-'0',__ch = getchar();}
LL gcd(LL _a, LL _b){if(!_b) return _a;else return gcd(_b, _a%_b);}
//head
double g[15][maxn];
double dp[maxn][maxn];
int n, m;
void read(void)
{
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
scanf("%lf", &g[i][j]);
}
void init(void)
{
for(int i = 0; i <= m; i++)
for(int j = 0; j < (1<<n); j++)
dp[i][j] = -1;
}
void work(int _)
{
dp[0][0] = 0;
int tt = (1 << n) - 1;
for(int i = 0; i < m; i++)
for(int j = 0; j <= tt; j++) {
if(dp[i][j] <= -0.5) continue;
for(int k = 0; k < n; k++) {
if(j & (1 << k)) continue;
if((j | (1 << k)) != tt) dp[i+1][j | (1 << k)] = max(dp[i+1][j | (1 << k)], dp[i][j] + g[k][i]);
else dp[i+1][0] = max(dp[i+1][0], dp[i][j] + g[k][i]);
}
}
double ans = 0;
for(int i = 0; i <= tt; i++) ans = max(dp[m][i], ans);
printf("Case #%d: %.5f
", _, ans);
}
int main(void)
{
int _, __;
while(scanf("%d", &_)!=EOF) {
__ = 0;
while(_--) {
read();
init();
work(++__);
}
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
[HDU] 4089 활성화 확률 DPdp[i][j]를 모두 i개인의 대기열인 Tomato가 j위 서버가 마비될 확률로 역추를 사용하면 우리는 상태 이동 방정식을 얻을 수 있다. i == 1 : dp[1][1] = dp[1][1] * p1 + dp[1]...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.