ZOJ3158 【DFS】
2024-09-29 22:36:08
题意:
从上往下切割,不能切边缘,然后问你两个差值,要小于给出的值。
思路:
直接爆搜,枚举每一行的劈开位置;
#include<bits/stdc++.h>
using namespace std; const int N=1e2+10;
const int INF=0x3f3f3f3f; int n,m;
int sum[N][N];
int ssum,ans; void DFS(int num,int summ)
{
int temp;
for(int i=1;i<m;i++)
{
temp=summ+sum[num][i];
if(num==n)
{
ans=min(ans,abs(temp-ssum+temp));
}
else
DFS(num+1,temp);
}
} int main()
{
int flag;
while(~scanf("%d%d",&n,&m))
{
int dd;
memset(sum,0,sizeof(sum));
ssum=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&dd);
ssum+=dd;
sum[i][j]=sum[i][j-1]+dd;
}
}
scanf("%d",&flag);
ans=INF;
DFS(1,0);
if(ans>flag)
puts("You'd better buy another one!");
else
printf("%d\n",ans);
}
return 0;
}
最新文章
- spring boot开发入门
- UWP学习记录5-设计和UI之控件和模式2
- Yii 读取CVS文件内容插入到数据库
- 《Eclipse中的一些快捷键》
- Linux chkconfig命令
- IHttpModule在webconfig中的注册
- AQS 与 LockSupport
- java8新特性笔记
- C#中的Collection 2
- 在stm32上移植wpa_supplicant(一)
- 顺序容器的insert使用方法
- python测试框架nose
- app.config 配置多项 配置集合 自定义配置(3)
- Seattle Traffic construction projects punlication
- 如何找出单链表中的倒数第k个元素
- Go之viper配置
- 20155320 Exp9 Web安全基础
- bing背单词交互流程 - Chongyang Bai
- [转]MySQL DBA面试全揭秘
- Elasticsearch 6.x 的分页查询数据