hdu 4568 Hunter

Hunter

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1110    Accepted Submission(s): 312


Problem Description
  One day, a hunter named James went to a mysterious area to find the treasures. James wanted to research the area and brought all treasures that he could.
  The area can be represented as a N*M rectangle. Any points of the rectangle is a number means the cost of research it,-1 means James can't cross it, James can start at any place out of the rectangle, and explore point next by next. He will move in the rectangle and bring out all treasures he can take. Of course, he will end at any border to go out of rectangle(James will research every point at anytime he cross because he can't remember whether the point are researched or not).
  Now give you a map of the area, you must calculate the least cost that James bring out all treasures he can take(one point up to only one treasure).Also, if nothing James can get, please output 0.
 

Input
  The input consists of T test cases. The number of test cases T is given in the first line of the input. Each test case begins with a line containing 2 integers N M , (1<=N,M<=200), that represents the rectangle. Each of the following N lines contains M numbers(0~9),represent the cost of each point. Next is K(1<=K<=13),and next K lines, each line contains 2 integers x y means the position of the treasures, x means row and start from 0, y means column start from 0 too.
 

Output
  For each test case, you should output only a number means the minimum cost.
 

Sample Input
  
  
2 3 3 3 2 3 5 4 3 1 4 2 1 1 1 3 3 3 2 3 5 4 3 1 4 2 2 1 1 2 2
 

Sample Output
  
  
8 11
 


先A*搜索求出每个点之间的最短路,把矩阵外面看成第0点,所以一共有k+1个点,注意是有向图!!!!!从a进入b,和b进入a不一样。

然后就是TSP。。

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;

typedef long long ll;
#define rep(i,s,t) for(int i=s;i<t;i++)
#define red(i,s,t) for(int i=s-1;i>=t;i--)
#define ree(i,now) for(int i=head[now];i!=-1;i=edge[i].next)
#define clr(a,v) memset(a,v,sizeof a)
#define max(a,b) (a<b?b:a)
#define min(a,b) (a<b?a:b)
#define abs(a) ((a)<0?-(a):(a))
#define L t<<1
#define R t<<1|1
#define MID int mid=(l+r)>>1

inline int input(){
    int ret=0;bool isN=0;char c=getchar();
    while(c<'0' || c>'9'){
        if(c=='-') isN=1;
        c=getchar();
    }
    while(c>='0' && c<='9'){
        ret=ret*10+c-'0';
        c=getchar();
    }
    return isN?-ret:ret;
}

inline void output(int x){
    if(x<0){
        putchar('-');x=-x;
    }
    int len=0,data[11];
    while(x){
        data[len++]=x%10;x/=10;
    }
    if(!len)    data[len++]=0;
    while(len--)
        putchar(data[len]+48);
    putchar('\n');
}

const int N=14;
const int MAXN=210;
const int dx[]={1,-1,0,0};
const int dy[]={0,0,1,-1};
int map[MAXN][MAXN];
int dis[N][N];
int id[MAXN][MAXN];
int dp[1<<N][N];
int t,n,m,k,x[N],y[N];
bool vis[N];
bool has[MAXN][MAXN];

struct node{
    int x,y,dis;
    bool operator < (const node &a) const{
        return dis>a.dis;
    }
};
priority_queue<node>q;
inline void bfs(int x,int y){
    while(!q.empty()) q.pop();
    clr(vis,0);clr(has,0);
    node vn,vw;
    vn.x=x,vn.y=y,vn.dis=0;
    has[x][y]=1;
    q.push(vn);
    int num=0;
    while(!q.empty()){
        vn=q.top();q.pop();
        if(vn.x==-1 || vn.x==n || vn.y==-1 || vn.y==m){
            if(!vis[0]){
                dis[id[x][y]][0]=vn.dis;
                vis[0]=1;
                num++;
            }
            continue;
        }
        else if(id[vn.x][vn.y]!=-1 && !vis[id[vn.x][vn.y]]){
            dis[id[x][y]][id[vn.x][vn.y]]=vn.dis;
            vis[id[vn.x][vn.y]]=1;
            num++;
        }
        if(num == k+1) break;
        rep(i,0,4){
            int a=vn.x+dx[i],b=vn.y+dy[i];
            if(a>=0&&a<n&&b>=0&&b<m&&!has[a][b]&&map[a][b]!=-1){
                vw.x=a,vw.y=b,vw.dis=vn.dis+map[a][b];
                has[a][b]=1;
                q.push(vw);
            }
            else if(a==-1 || a==n || b==-1 || b==m){
                vw.x=a,vw.y=b,vw.dis=vn.dis;
                q.push(vw);
            }
        }
    }
}

int main(){
    t=input();
    rep(ca,0,t){
        n=input();m=input();
        rep(i,0,n) rep(j,0,m) map[i][j]=input();
        clr(id,-1);k=input();
        rep(i,1,k+1){
            x[i]=input(),y[i]=input();
            id[x[i]][y[i]]=i;
        }
        clr(dis,0);
        rep(i,1,k+1){
            bfs(x[i],y[i]);
        }
        rep(i,1,k+1){
            dis[0][i]=dis[i][0]+map[x[i]][y[i]];
        }
       /* rep(i,0,k+1){
            rep(j,0,k+1){
                printf("%d ",dis[i][j]);
            }
            printf("\n");
        }*/
        clr(dp,-1);
        k++;
        rep(i,0,k) dp[1<<i][i]=dis[0][i];
        int all=(1<<k);
        rep(i,0,all){
            rep(j,0,k){
                if(i&(1<<j) && dp[i][j]!=-1){
                    rep(r,0,k){
                        if(!(i&(1<<r))){
                            int val=dp[i][j]+dis[j][r];
                            int nxt=(i|(1<<r));
                            if(dp[nxt][r]==-1 || val<dp[nxt][r]){
                                dp[nxt][r]=val;
                            }
                        }
                    }
                }
            }
        }
        output(dp[all-1][0]);
    }
    return 0;
}


深度学习是机器学习的一个子领域,它基于人工神经网络的研究,特别是利用多层次的神经网络来进行学习和模式识别。深度学习模型能够学习数据的高层次特征,这些特征对于图像和语音识别、自然语言处理、医学图像分析等应用至关重要。以下是深度学习的一些关键概念和组成部分: 1. **神经网络(Neural Networks)**:深度学习的基础是人工神经网络,它是由多个层组成的网络结构,包括输入层、隐藏层和输出层。每个层由多个神经元组成,神经元之间通过权重连接。 2. **前馈神经网络(Feedforward Neural Networks)**:这是最常见的神经网络类型,信息从输入层流向隐藏层,最终到达输出层。 3. **卷积神经网络(Convolutional Neural Networks, CNNs)**:这种网络特别适合处理具有网格结构的数据,如图像。它们使用卷积层来提取图像的特征。 4. **循环神经网络(Recurrent Neural Networks, RNNs)**:这种网络能够处理序列数据,如时间序列或自然语言,因为它们具有记忆功能,能够捕捉数据中的时间依赖性。 5. **长短期记忆网络(Long Short-Term Memory, LSTM)**:LSTM 是一种特殊的 RNN,它能够学习长期依赖关系,非常适合复杂的序列预测任务。 6. **生成对抗网络(Generative Adversarial Networks, GANs)**:由两个网络组成,一个生成器和一个判别器,它们相互竞争,生成器生成数据,判别器评估数据的真实性。 7. **深度学习框架**:如 TensorFlow、Keras、PyTorch 等,这些框架提供了构建、训练和部署深度学习模型的工具和库。 8. **激活函数(Activation Functions)**:如 ReLU、Sigmoid、Tanh 等,它们在神经网络中用于添加非线性,使得网络能够学习复杂的函数。 9. **损失函数(Loss Functions)**:用于评估模型的预测与真实值之间的差异,常见的损失函数包括均方误差(MSE)、交叉熵(Cross-Entropy)等。 10. **优化算法(Optimization Algorithms)**:如梯度下降(Gradient Descent)、随机梯度下降(SGD)、Adam 等,用于更新网络权重,以最小化损失函数。 11. **正则化(Regularization)**:技术如 Dropout、L1/L2 正则化等,用于防止模型过拟合。 12. **迁移学习(Transfer Learning)**:利用在一个任务上训练好的模型来提高另一个相关任务的性能。 深度学习在许多领域都取得了显著的成就,但它也面临着一些挑战,如对大量数据的依赖、模型的解释性差、计算资源消耗大等。研究人员正在不断探索新的方法来解决这些问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值