poj1923 Fourier's Lines
思路:
记忆化搜索。
n条直线的交点方案数
=(n-r)条平行线与r条直线交叉的交点数+r条直线本身的交点方案
=(n-r)*r+r条直线之间本身的交点方案数(0<r<=n)
于是可以枚举r,递归来计算。
实现:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int dp[][];
int dfs(int n, int m)
{
if (m < || m > n * (n - ) >> ) return ;
if (!m) return ;
if (dp[n][m] != -) return dp[n][m];
for (int i = ; i <= n; i++)
{
if (dfs(n - i, m - i * (n - i)))
return dp[n][m] = ;
}
return dp[n][m] = ;
} int main()
{
int kase = , n, m;
memset(dp, -, sizeof(dp));
while (cin >> n >> m, n + m)
{
if (dfs(n, m))
cout << "Case " << kase++ << ": " << n << " lines with exactly " << m << " crossings can cut the plane into " << n + m + << " pieces at most." << endl;
else
cout << "Case " << kase++ << ": " << n << " lines cannot make exactly " << m << " crossings." << endl;
}
return ;
}
poj1923 Fourier's Lines的更多相关文章
- extracting lines bases a list using awk
extracting lines bases a list using awk awk 'NR==FNR{a[$1]=$0; next}($1 in a){print a[$1]"\n&qu ...
- Enum:Game of Lines(POJ 3668)
画直线 题目大意:给定一些点集,要你找两点之间的连线不平行的有多少条 数据量比较少,直接暴力枚举,然后放到set查找即可 #include <iostream> #include < ...
- 我的常用mixin 之 lines
/** * 最多显示 $lineCount 行 * lines * * example: * @include lines; * @include lines(3); */ @mixin lines( ...
- uva 1471 defence lines——yhx
After the last war devastated your country, you - as the king of the land of Ardenia - decided it wa ...
- POJ 1269 Intersecting Lines --计算几何
题意: 二维平面,给两条线段,判断形成的直线是否重合,或是相交于一点,或是不相交. 解法: 简单几何. 重合: 叉积为0,且一条线段的一个端点到另一条直线的距离为0 不相交: 不满足重合的情况下叉积为 ...
- POJ 1269 Intersecting Lines【判断直线相交】
题意:给两条直线,判断相交,重合或者平行 思路:判断重合可以用叉积,平行用斜率,其他情况即为相交. 求交点: 这里也用到叉积的原理.假设交点为p0(x0,y0).则有: (p1-p0)X(p2-p0) ...
- [CareerCup] 13.1 Print Last K Lines 打印最后K行
13.1 Write a method to print the last K lines of an input file using C++. 这道题让我们用C++来打印一个输入文本的最后K行,最 ...
- Codeforces 593B Anton and Lines
LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output st ...
- 简单几何(直线位置) POJ 1269 Intersecting Lines
题目传送门 题意:判断两条直线的位置关系,共线或平行或相交 分析:先判断平行还是共线,最后就是相交.平行用叉积判断向量,共线的话也用叉积判断点,相交求交点 /********************* ...
随机推荐
- CentOS 7最小安装后,手动连接网络
时间:2015-12-12 00:53来源:blog.51cto.com 作者:XD 举报 点击:3679次 CentOS中最小安装,由于默认的网卡没有激活,所以无法连接到网络. 设置如下: sucd ...
- 【Python】python扩展
当python的基本功能无法满足要求.或者是为了保密源码(.py).遇到性能瓶颈时,我们经常要扩展python,扩展语言能够是C/C++.Java.C#等. 为python创建扩展须要三个基本的步骤: ...
- node-load module
javscript :脚本建共享全局名称空间(全局污染). node:实现CommonJS(公共)模块标准. Node加载模块,有两种方式: 1.通过名称 除非是核心模块,否则被引用的模块最后都会映射 ...
- JSP简单练习-包装类综合应用实例
<%@ page contentType="text/html; charset=gb2312" %><!-- JSP指令标签 --> <%@ pag ...
- has实现 更新视图但不重新加载页面原理
URL中#符号本身以及它的字符称之为hash,可以通过window.location.hash获取.hash具有如下特点: 1.has虽然出现在URL中,但不会被包括在http请求中.因此,改变has ...
- Unity3D & C# 设计模式--23
Unity3D & C#Design Patterns 23 design patterns. Creational Patterns 1. Abstract Factory抽象工厂 创 ...
- NOIP 2013 花匠 神仙操作
题目:https://www.luogu.org/problemnew/show/P1970 今天又学习了一个新的神仙操作: 标签是DP,想了一下,没什么心情写,默默打开题解——(狂喜!) 一位大佬( ...
- bzoj4870
http://www.lydsy.com/JudgeOnline/problem.php?id=4870 矩阵快速幂... 人话题意:从nk个物品里选模k余r个物品,问方案数模P 那么我们有方程 f[ ...
- 将数据从数据仓库Hive导入到MySQL
1.启动Hadoop,hive,mysql 2.在mysql中建表(需要导入数据的) mysql> CREATE TABLE `dbtaobao`.`user_log` (`user_id` v ...
- 32.ExtJS简单的动画效果
转自:http://blog.sina.com.cn/s/blog_74684ec501015lhq.html 说明:这篇文章的大部分内容来源于网上,经过自己实现其效果后,整理如下: 在进行 Java ...