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.4.5


    杨老师的照相排列

    首先要将问题抽象

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <algorithm>
    #include <cstring>
    
    using namespace std;
    typedef long long ll;
    const int N = 31;
    
    int n = 0;
    ll f[N][N][N][N][N];
    
    int main()
    {
        while(cin >> n , n)
        {
            int s[5] = {0};
            for (int i = 0; i < n; i ++ ) cin >> s[i];
    
            memset(f, 0, sizeof f);
            f[0][0][0][0][0] = 1;
            for (int a = 0; a <= s[0]; a ++ )
                for (int b = 0; b <= min(a, s[1]); b ++ )
                    for (int c = 0; c <= min(b, s[2]); c ++ )
                        for (int d = 0; d <= min(c, s[3]); d ++ )
                            for (int e = 0; e <= min(d, s[4]); e ++ )
                            {
                                ll &x = f[a][b][c][d][e];
                                if (a && a - 1 >= b) x += f[a - 1][b][c][d][e];
                                if (b && b - 1 >= c) x += f[a][b - 1][c][d][e];
                                if (c && c - 1 >= d) x += f[a][b][c - 1][d][e];
                                if (d && d - 1 >= e) x += f[a][b][c][d - 1][e];
                                if (e) x += f[a][b][c][d][e - 1];
                            }
            cout << f[s[0]][s[1]][s[2]][s[3]][s[4]] << endl;
        }
        return 0;
    }
    

    luogu-P1057 传球游戏

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    
    using namespace std;
    const int N = 50;
    int n , m;
    /*
    now  表示当前数字
    cnt  表示当前剩余步数
    */
    int f[N][N];
    int dfs(int now ,int cnt)
    {
    	//cout << now << " " << cnt << endl;
    	if(cnt < 0)return 0;
    	if(now == 0 && cnt == 0)return 1;
    	if(f[now][cnt] != -1)return f[now][cnt];
    	// 可以向左边走也可以向右边走
    	// 左边
    	int ans = dfs((now + n - 1) % n,cnt - 1);
    	ans += dfs((now + 1) % n, cnt - 1);
    
    	return f[now][cnt] = ans;
    }
    int main()
    {
    	cin >> n >> m;
    	memset(f , -1 , sizeof f);
    	cout << dfs(0 , m);
    	return 0;
    }
    

    P1021 邮票面值设计

    /*
    如果想要枚举出来[1-MAX]之间的所有数
    必须出现有 [1.....]
    所以规定 w[0] = 1;
    往后枚举 k - 1 位
    
    递归出口: 
    
    	找到出口
    递归分支:
    
        1. 枚举上界限
           令当前位要枚举的起始边界为 int x = w[i-1] + 1;
           得到当前组合能枚举出来的连续MAX
    	2.  
    
    */
    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <algorithm>
    #include <cstring>
    
    using namespace std;
    const int N = 30;
    const int M = 50005;
    int n , m;
    int f[M] , a[N] , ans[N],maxc = 0;
    int dp(int k)
    {
    	memset(f, 63 , sizeof f);
    	f[0] = 0;
    	for(int i = 1;i <= k ;i ++)
    	{
    		for(int j = a[i] ;j <= a[k] * n ;j ++)
    		{
    			if(f[j-a[i]] < n)
    				f[j] = min(f[j],f[j-a[i]] + 1);
    		}
    	}
    	int x = 0;
    	while(f[x+1] <= 100)x++;
    	return x;
    }
    void dfs(int k)
    {
    	if(k == m + 1)
    	{
    		int t = dp(k - 1);
    		if(t > maxc)
    		{
    			maxc = t;
    			memcpy(ans , a , sizeof ans);
    		}
    		return;
    	}
    	int last = dp(k - 1);
    	for(int i = a[k - 1] + 1; i <= last + 1 ;i ++)
    	{
    		a[k] = i;
    		dfs(k + 1);
    		a[k] = 0;
    	}
    }
    int main()
    {
    	cin >> n >> m;
    	a[1] = 1;
    	dfs(2);
    	for(int i = 1;i <= m ;i ++)printf("%d ",ans[i]);
    	printf("
    MAX=%d",maxc);
    	return 0;
    }
    
    
  • 相关阅读:
    asp.net 框架接触(2)
    解决:C++ 中 main函数 wmain函数 _tmain函数 WinMain函数 wWInMain函数 _tWinMain函数的区别
    实现:创建/复制/移动文件API
    实现:类模板的数组类封装
    python3 解析shodan_json数据
    实现:API实现创建用户并且添加至管理员
    学习:类模板
    网展cms后台任意文件删除和sql注入
    选择排序
    实现:函数模板实现不同数据类型数组进行排序
  • 原文地址:https://www.cnblogs.com/wlw-x/p/12648884.html
Copyright © 2011-2022 走看看