poj 3390 DP
来源:互联网 发布:网络理财诈骗案 编辑:程序博客网 时间:2024/05/01 13:05
import java.io.*;import java.util.*;class line{ }public class Main { public static void main(String[] args) throws Exception { Scanner scan = new Scanner(System.in); int numbers = scan.nextInt(); while(numbers-->0){ int chars = scan.nextInt(); //length limitation of each line int size = scan.nextInt(); //words in text int arr[] = new int[size+2]; int dp[] = new int[size+2]; for(int i=1;i<=size;i++){ arr[i] = scan.nextInt(); } for(int i=1;i<=size;i++){ dp[i] = dp[i-1] + (int)Math.pow(chars-arr[i],2); int sum = arr[i]; for(int j=i-1;j>0&&sum+arr[j]+1<=chars;j--){ sum+=arr[j]+1; int temp = dp[j-1]+(int)Math.pow(chars-sum,2); dp[i] = Math.min(dp[i],temp); } } System.out.println(dp[size]); } }};
这个题目说点啥好呢,解空间开的好猥琐啊,这个真不知道怎么说了,想不出来
- poj 3390 DP
- poj dp
- 【dp】POJ
- 【dp】POJ
- [DP] POJ
- [DP] POJ
- [DP] POJ
- 【dp】POJ
- POJ 3390 Print Words in Lines(DP)
- POJ 3390 Print Words in Lines(DP)
- POJ 3670 && POJ 3671 (dp)
- 【DP】 POJ 1080
- poj 1163经典DP
- poj 1088 滑雪(DP)
- poj 1770 树形dp
- POJ 1179 Polygon(DP)
- POJ 1221 dp
- POJ 1953 DP
- 更多关于矩阵和队列
- 常用JS
- 关于JAVA的值传递和引用传递&String
- javascript数组的方法
- POJ-1001 Exponentiation 高精度
- poj 3390 DP
- [88]Merge Sorted Array
- 【技术类】【且听我说“镶嵌数据集”】10、镶嵌数据集影像管理与应用示例(完)
- uva10158
- DLL的灾难---DEBUG与RELEASE版本不能交叉调用
- js xml实现全国地区级联(Firefox IE Chrome)
- Python完全新手教程
- JS关闭窗口不提示或JS关闭页面的几种方法
- Android开发之Intent跳转到系统应用中的拨号界面、联系人界面、短信界面 .相机.录影机....