51nod1625(枚举&贪心)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625
题意:中文题诶~
思路:枚举+贪心
一开始写的行和列同时枚举,写的时候就担心可能行和列会相互影响,提交结果证明我的担心是对的;
注意到1 <= n <= 10, 1 <= m <= 200,n很小,那么所有行的状态不超过1024种,所以可以枚举所有行的状态,对于每一种行的状态下再对列贪心。。
枚举行的所有状态可以用dfs。。
代码:
#include <iostream>
#include <string.h>
#define ll long long
using namespace std; const int MAXN=;
ll a[MAXN][MAXN*], b[MAXN][MAXN*], vis[MAXN], ans=, m, n, x, k; ll get_ans(void){
ll ans=;
for(int i=; i<n; i++){
for(int j=; j<m; j++){
ans+=b[i][j];
}
}
return ans;
} void solve(void){
int num=k;
memcpy(b, a, sizeof(a));
for(int i=; i<n; i++){
if(vis[i]&&num>){
num--;
for(int j=; j<m; j++){
b[i][j]=x;
}
}
}
while(num){
ll fj=-, vj=;
for(int j=; j<m; j++){
ll cnt=;
for(int i=; i<n; i++){
cnt+=x-b[i][j];
}
if(cnt>vj){
vj=cnt;
fj=j;
}
}
if(fj!=-){
num--;
for(int i=; i<n; i++){
b[i][fj]=x;
}
}else break;
}
ans=max(ans, get_ans());
} void dfs(int x){
if(x>=n){
solve();
return;
}
vis[x]=;
dfs(x+);
vis[x]=;
dfs(x+);
} int main(void){
cin >> n >> m >> x >> k;
for(int i=; i<n; i++){
for(int j=; j<m; j++){
cin >> a[i][j];
}
}
dfs();
cout << ans << endl;
return ;
}
51nod1625(枚举&贪心)的更多相关文章
- D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心
D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 枚举+贪心 HDOJ 4932 Miaomiao's Geometry
题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...
- [BZOJ 1028] [JSOI2007] 麻将 【枚举+贪心判断】
题目链接:BZOJ - 1028 题目分析 枚举听的是哪种牌,再枚举成对的是哪种牌,再贪心判断: 从1到n枚举每一种牌,如果这种牌的个数小于0,就返回不合法. 将这种牌的张数 % 3, 剩下的只能和 ...
- 【枚举+贪心】【TOJ3981】【ICPC Balloons】
给你N种不同颜色气球,每种气球有个数目 count[i],给的同种颜色气球可能是L尺寸,或M尺寸. M个问题,每个问题有个解决人数ac[i]. 每个问题 要分配一种颜色的气球,尺寸要一样 现在 这些气 ...
- 【枚举+贪心】【ZOJ3715】【Kindergarten Electiond】
题目大意: n 个人 在选取班长 1号十分想当班长,他已经知道其他人选择了谁,但他可以贿赂其他人改选他,问贿赂的最小值 ps.他自己也要投一个人 要处理一个问题是,他自己投谁 其实这个问题在这种局面下 ...
- FZU 2252 Yu-Gi-Oh!(枚举+贪心)
Problem 2252 Yu-Gi-Oh! Accept: 105 Submit: 628 Time Limit: 1000 mSec Memory Limit : 32768 KB ...
- UVALive 6912 Prime Switch 暴力枚举+贪心
题目链接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show ...
- bzoj1050[HAOI2006]旅行comf(枚举+贪心+并查集)
Description 给你一个无向图,N(N<=500)个顶点, M(M<=5000)条边,每条边有一个权值Vi(Vi<30000).给你两个顶点S和T,求一条路径,使得路径上最大 ...
- AtCoder - 2565 枚举+贪心
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing thi ...
随机推荐
- hdu5258简单枚举
百度之星复赛第一题.不明白这么水的题为何一堆人没过...这些人是咋晋级复赛的呢... /* * Author : ben */ #include <cstdio> #include < ...
- 【LeetCode】Construct Binary Tree from Preorder and Inorder Traversal
Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...
- Machine Learning in Action(7) 回归算法
按照<机器学习实战>的主线,结束有监督学习中关于分类的机器学习方法,进入回归部分.所谓回归就是数据进行曲线拟合,回归一般用来做预测,涵盖线性回归(经典最小二乘法).局部加权线性回归.岭回归 ...
- CMTime 与 CMTimeMakeWithSeconds
1.首先先看代码,这段代码的作用就是要让视频播放区域有个封面.不会显的太空当. - (void)avPlayerDidPlayed:(NSNotification *)noti { [_avPlaye ...
- spring cloud服务注册与发现无法发现的可能原因
1.注册中心服务端默认90秒检测一次,看服务是否还存活,不存活则删除掉服务,还存活则继续注册上去 2. spring: profiles: dev cloud: config: name: clean ...
- LightOJ1370 Bi-shoe and Phi-shoe —— 欧拉函数
题目链接:https://vjudge.net/problem/LightOJ-1370 1370 - Bi-shoe and Phi-shoe PDF (English) Statistics ...
- HDU3723 Delta Wave —— 卡特兰数
题目链接:https://vjudge.net/problem/HDU-3723 Delta Wave Time Limit: 6000/3000 MS (Java/Others) Memory ...
- Appium java 环境配置
一.安装node.js 下载地址:http://pan.baidu.com/s/1qYyNDm8 点击安装,next下一步就ok. 安装完成,命令行输入:npm 这样显示的话就ok了. 二.下载Ap ...
- AndroidManifest中的Intent-filter标签
经过测试,intent-filter标签中的: 1. <action android:name="android.intent.action.MAIN" /> 代表这是 ...
- SPOJ:Another Longest Increasing Subsequence Problem(CDQ分治求三维偏序)
Given a sequence of N pairs of integers, find the length of the longest increasing subsequence of it ...