zoukankan      html  css  js  c++  java
  • 每日算法

    每日算法

    those times when you get up early and you work hard; those times when you stay up late and you work hard; those times when don’t feel like working — you’re too tired, you don’t want to push yourself — but you do it anyway. That is actually the dream. That’s the dream. It’s not the destination, it’s the journey. And if you guys can understand that, what you’ll see happen is that you won’t accomplish your dreams, your dreams won’t come true, something greater will. mamba out


    那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~

    2020.3.30


    今天网太炸 一天都没打开cfQAQ

    luogu-P1434 [SHOI2002]滑雪

    重温经典好题

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <vector>
    
    using namespace std;
    const int N = 105;
    
    int a[N][N] , f[N][N] , n , m;
    int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
    
    bool inmap(int x,int y)
    {
    	return x >= 1 && x <= n && y >= 1 && y <= m;	
    }
    int dfs(int x,int y)
    {
    	if(f[x][y] != 0)return f[x][y];
    	int ans = 0;
    	for(int i = 0;i < 4 ;i ++)
    	{
    		int nx = x + dir[i][0];
    		int ny = y + dir[i][1];
    		if(inmap(nx,ny) && a[x][y] < a[nx][ny])
    		{
    			ans = max(dfs(nx,ny),ans);
    		}
    	}
    	if(ans == 0)return f[x][y] = 1;
    	else return f[x][y] = ans + 1;
    }
    int main()
    {
    	cin >> n >> m;
    	for(int i = 1;i <= n ;i ++)
    	{
    		for(int j = 1;j <= m ;j ++)
    			scanf("%d",&a[i][j]);
    	}
    	int ans = 0;
    	for(int i = 1;i <= n ;i ++)
    	{
    		for(int j = 1;j <= n ;j ++)
    		{
    			if(!f[i][j])
    			{
    				ans = max(dfs(i , j),ans);
    			}
    		}
    	}
    	cout << ans << endl;
    	return 0;
    } 
    

    luogu-P2196 挖地雷

    也许是我还没领悟到dp得精髓我觉得爆搜真舒服
    tips:当成有向图+记忆化轻而易举AC

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    
    using namespace std;
    const int N = 25;
    
    int n , w[N] , f[N];
    bool vis[N];
    vector<int> a[N];
    int path[N];
    // u : 当前 
    // 
    int ans = 0;
    int dfs(int u)
    {
    	if(f[u] != 0)return f[u];
    	int t = 0, cur = 0;
    	for(int i = 0;i < a[u].size();i ++)
    	{
    		int x = dfs(a[u][i]) + w[a[u][i]];
    		if(x > t)
    		{
    			t = x;
    			cur = a[u][i];
    		} 
    	}
    	path[u] = cur;
    	return f[u] = t;
    }
    
    int main()
    {
    	cin >> n;
    	for(int i = 1;i <= n ;i ++)scanf("%d",&w[i]);
    	int x = 0;
    	for(int i = 1;i <= n - 1;i ++)
    	{
    		for(int j = i + 1;j <= n;j ++)
    		{
    			scanf("%d",&x);
    			if(x == 1){
    				a[i].push_back(j);
    			}
    		}
    	}
    	
    	int ans = 0, now = 0;
    	for(int i = 1;i <= n ;i ++)
    	{
    		int t = dfs(i) + w[i];
    		if(t > ans)
    		{
    			ans = t;now = i;
    		} 
    	}
    	cout << now << " ";
    	while(now <= n)
    	{
    		if(path[now]){
    			cout << path[now] << " ";
    			now = path[now];
    		}else break;
    	}
    	cout << endl << ans << endl;
    	return 0;
    }
    
  • 相关阅读:
    MongoDB数据导入hbase + 代码
    Hbase批量插入优化记录
    net.sf.fjep.fatjar_0.0.32 eclipse4.x 可以用的jar包
    %E3%80%90%E7%BD%91%E7%BB%9C%E7%BC%96%E7%A8%8B%E3%80%91
    学习《深度学习入门:基于Python的理论与实现》高清中文版PDF+源代码
    《Python生物信息学数据管理》中文PDF+英文PDF+代码
    推荐《R数据可视化手册》高清英文版PDF+中文版PDF+源代码
    学习优化《机器学习与优化》中文PDF+英文PDF
    入门python:《Python编程从入门到实践》中文PDF+英文PDF+代码学习
    推荐《SQL基础教程(第2版)》中文PDF+源代码+习题答案
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12602267.html
Copyright © 2011-2022 走看看