ural1005 Stone Pile (枚举)
来源:互联网 发布:ubuntu 16.04 下载 编辑:程序博客网 时间:2024/05/17 04:40
枚举n个石头的状态(即分在左还是右),然后找到答案最小的状态。
#include <bits/stdc++.h>using namespace std;int a[25];int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &a[i]); int ans = 0x3f3f3f3f; for (int i = 0; i < (1 << n); i++) { int l = 0, r = 0; for (int j = 0; j < n; j++) { if (i & (1 << j)) l += a[j]; else r += a[j]; } ans = min(ans, abs(l - r)); } printf("%d\n", ans); return 0;}
0 0
- ural1005 Stone Pile (枚举)
- Ural1005-Stone Pile
- URAL1005 Stone Pile
- URAL1005 - Stone Pile - 动态规划
- URAL1005 Stone Pile 01背包
- URAL1005 - Stone Pile - 深度优先搜索
- 【枚举】Stone Pile
- ural 1005 stone pile
- ural 1005. Stone Pile
- 1005. Stone Pile
- ural 1005 Stone Pile
- timus 1005 stone pile
- URAL 1005 Stone Pile
- URAL 1005 Stone Pile
- URAL 1005 Stone Pile
- ural 1005 Stone Pile
- URAL 1005 Stone Pile
- URAL 1005 Stone Pile
- 百度uedit禁止转义及关于模板语言 Mustache
- Sublime text安装以及常用插件
- Android 基础面试题(一)
- 尺取法(1)
- javascript面相对象编程
- ural1005 Stone Pile (枚举)
- 二分练习
- Java对象排序、中文排序、SortedSet排序使用和源码讲解
- (1)内存四区
- 关于堆的判断 (堆+map)
- spring framework 各版本源码下载地址
- MySQL报错: Found option without preceding group in config file:XXX; Fatal error in defaults handling.
- vue-router 路由
- NYOJ1272表达式求值(2)