BestCoder

已解决题目列表
[King’s Cake][1]
[King’s Phone][2]
[King’s Order][3]
[King’s Game][1]
Read more

BestCoder

已解决题目列表
[KK’s Steel][1]
[KK’s Point][2]
[KK’s Number][3]
Read more

BestCoder

已解决题目列表
[Jam’s math problem][1]
[Jam’s balance][2]
[Jam’s maze][3]
Read more

BestCoder

1001 Clarke and minecraft

玩过MC无压力

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/** Sep 19, 2015 7:12:36 PM
* PrjName:Bc56-01
* @author Semprathlon
*/
import java.io.*;
import java.util.*;
public class Main {

/**
* @param args
*/
final static int maxn=110;
static int cnt;
static int[] w;
static HashMap<Integer, Integer> mp=new HashMap<Integer,Integer>();
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
InputReader in=new InputReader(System.in);
PrintWriter out=new PrintWriter(System.out);
int T=in.nextInt();
//h=new int[maxn];
w=new int[maxn];
while(T-->0){
int n=in.nextInt();
cnt=0;
mp.clear();
Arrays.fill(w, 0);
for(int i=1;i<=n;i++){
int k=in.nextInt();
if (mp.containsKey(k))
w[mp.get(k)]+=in.nextInt();
else{
w[cnt]+=in.nextInt();
mp.put(k, cnt++);
}
}
int sum=0;
for(int i=0;i<cnt;i++)
sum+=(w[i]+63)/64;
out.println((sum+35)/36);
}
out.flush();
out.close();
}
}

1002 Clarke and problem

第一时间想到的是容斥,而后才逐渐醒悟过来是DP。。。
另外mod的遗漏又错了一发。。。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/** Sep 19, 2015 7:24:54 PM
* PrjName:Bc56-02
* @author Semprathlon
*/
import java.io.*;
import java.util.*;
public class Main {

/**
* @param args
*/
final static int maxn=1010;
final static int high=1000000000;
final static int mod=1000000007;
//static int[] s=new int[maxn];
static int[][] f=new int[2][maxn];
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
InputReader in=new InputReader(System.in);
PrintWriter out=new PrintWriter(System.out);
int T=in.nextInt();
while(T-->0){
int n=in.nextInt();
int p=in.nextInt();
//Arrays.fill(s, 0, p, 0);
Arrays.fill(f[0], 0, p, 0);
f[0][0]=1;
int cnt=0;
//for(int j=0;j<p;j++)out.print(f[j]+" ");out.println();
for(int i=1;i<=n;i++){
int k=in.nextInt();
while(k<0) k+=p;
k%=p;
Arrays.fill(f[cnt^1], 0,p,0);
for(int j=0;j<p;j++){
f[cnt^1][(k+j)%p]+=f[cnt][j];
f[cnt^1][(k+j)%p]%=mod;
}
for(int j=0;j<p;j++){
f[cnt^1][j]+=f[cnt][j];
f[cnt^1][j]%=mod;
}
cnt^=1;
}
out.println(f[cnt][0]);

}
out.flush();
out.close();
}
}

1003 Clarke and puzzle

没有总结好Nim游戏的规律啊。。。超简单的代码

hdu 1204 糖果大战 概率过程

hdu 1204

通过本题接触到了存在于《概率论与数理统计》教材,但是不在学校教学范围内的概率过程知识。
接受这种新的认知,才能避免落入高中局限的概率观的窠臼。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/** Sep 5, 2015 9:45:04 PM
* PrjName:hdu1204
* @author Semprathlon
*/
import java.awt.Toolkit;
import java.io.*;
import java.util.*;
public class Main {
/**
* @param args
*/
static double pow(double n,int m){
double res=1;
while(m>0){
if ((m&1)>0) res=res*n;
n=n*n;
m>>=1;
}
return res;
}
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
InputReader in=new InputReader(System.in);
PrintWriter out=new PrintWriter(System.out);
while(in.nextLine()!=null){
int n=in.nextInt();
int m=in.nextInt();
double p=in.nextDouble();
double q=in.nextDouble();
if (n==0)
out.println("0.00");
else if (m==0)
out.println("1.00");
else if (p==0||q==1)
out.println("0.00");
else if (p==1||q==0)
out.println("1.00");
else{
double k=q*(1.0-p)/p/(1.0-q);
double ans=p==q?n*1.0/(m+n):(1.0-pow(k, n))/(1.0-pow(k, n+m));
out.println(String.format("%.2f", ans));
}
}
out.flush();
out.close();
}
}

2014 ACM/ICPC Asia Regional Anshan Online

hdu 5001 Walk 概率dp
其实就是这么直白,正难则反

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/** Sep 2, 2015 8:29:38 PM
* PrjName:hdu5001
* @author Semprathlon
*/
import java.io.*;
import java.util.*;

public class Main {

/**
* @param args
*/
static int n, m, d;
static int[] deg;
static int[][] u;
static double[][] f;

static double solve(int x) {
f = new double[d + 1][n + 1];
for (int i = 1; i <= n; i++)
f[0][i] = 1.0 / n;
for (int i = 1; i <= d; i++)
for (int j = 1; j <= n; j++) {
if (j == x)
continue;
for (int k = 1; k <= u[j][0]; k++)
f[i][u[j][k]] += f[i - 1][j] / u[j][0];
}
double ans = 0;
for (int i = 1; i <= n; i++)
if (i != x)
ans += f[d][i];
return ans;
}

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int T = in.nextInt();
while (T-- > 0) {
n = in.nextInt();
m = in.nextInt();
d = in.nextInt();
u = new int[n + 1][m + 1];
deg = new int[n + 1];
for (int i = 1; i <= m; i++) {
int x = in.nextInt();
deg[x]++;
int y = in.nextInt();
deg[y]++;
u[x][++u[x][0]] = y;
u[y][++u[y][0]] = x;
}

for (int i = 1; i <= n; i++)
out.println(String.format("%.6f", solve(i)));
}
out.flush();
out.close();
}

}

不知为何,printf+格式字符串会出现莫名的PE

hdu 4998 Rotate

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/** Sep 2, 2015 5:58:24 PM
* PrjName:hdu4998
* @author Semprathlon
*/
import java.io.*;
import java.util.*;

public class Main {

/**
* @param args
*/
final static double eps = 1e-5;
final static double pi = Math.acos(-1.0);

static int dcmp(double d) {
if (Math.abs(d) < eps)
return 0;
return d > 0 ? 1 : -1;
}

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int T = in.nextInt();
while (T-- > 0) {
int n = in.nextInt();
Point p1 = new Point(0, 0), q1 = new Point(p1);
Point p2 = new Point(0, 1), q2 = new Point(p2);
for (int i = 1; i <= n; i++) {
double x = in.nextDouble();
double y = in.nextDouble();
double a = in.nextDouble();
q1 = q1.rotate(x, y, a);
q2 = q2.rotate(x, y, a);
}
Vector v1 = new Vector(p1, q1).normal();
Vector v2 = new Vector(p2, q2).normal();
Point o = Vector.GetLineIntersection(Point.mid(p1, q1), v1, Point.mid(p2, q2), v2);
double ans = Vector.angle(o, p1, q1);
if (Vector.cross(new Vector(o, p1), new Vector(o, q1)) < 0)
ans = 2 * pi - ans;
out.printf("%.5f %.5f %.5f\n", o.x, o.y, ans);
}
out.flush();
out.close();
}

static class Point {
double x, y;

Point() {
}

Point(double _x, double _y) {
x = _x;
y = _y;
}

Point(Point p) {
this(p.x, p.y);
}

boolean equals(Point p) {
return dcmp(x - p.x) == 0 && dcmp(y - p.y) == 0;
}

Point add(Point r) {
return new Point(x + r.x, y + r.y);
}

Point sub(Point r) {
return new Point(x - r.x, y - r.y);
}

Point mul(double r) {
return new Point(x * r, y * r);
}

Point move(double dx, double dy) {
return new Point(x + dx, y + dy);
}

Point rotate(double a) {
return new Point(x * Math.cos(a) - y * Math.sin(a), x * Math.sin(a) + y * Math.cos(a));
}

Point rotate(double dx, double dy, double a) {
return this.move(-dx, -dy).rotate(a).move(dx, dy);
}

static Point mid(Point a, Point b) {
return new Point((a.x + b.x) / 2.0, (a.y + b.y) / 2.0);
}
}

static class Vector extends Point {
Vector(double _x, double _y) {
x = _x;
y = _y;
}

Vector(Point a, Point b) {
this(b.x - a.x, b.y - a.y);
}

Vector(Point p) {
this(p.x, p.y);
}

static double angle(Vector a, Vector b) {
return Math.acos(dot(a, b) / a.length() / b.length());
}

static double angle(Point o, Point a, Point b) {
return angle(new Vector(o, a), new Vector(o, b));
}

double dot(Vector r) {
return x * r.x + y * r.y;
}

double cross(Vector r) {
return x * r.y - y * r.x;
}

double length() {
return Math.sqrt(this.dot(this));
}

Vector normal() {
double len = this.length();
return new Vector(-y / len, x / len);
}

static Point GetLineIntersection(Point p, Vector v, Point q, Vector w) {// 求直线交点
Vector u = new Vector(p.sub(q));
double t = cross(w, u) / cross(v, w);
return p.add(v.mul(t));
}

static Point GetLineIntersection(Point p, Point v, Point q, Point w) {
return GetLineIntersection(p, new Vector(v), q, new Vector(w));
}

static Vector add(Vector a, Vector b) {
return new Vector(a.add(b));
}

static double dot(Vector a, Vector b) {
return a.dot(b);
}

static double cross(Vector a, Vector b) {
return a.cross(b);
}

static double cross(Point o, Point a, Point b) {
return cross(new Vector(o, a), new Vector(o, b));
}

static double length(Vector r) {
return r.length();
}
}
}

说得好像很繁的样子

hdu 5000

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/** Sep 3, 2015 9:43:43 PM
* PrjName:hdu5000
* @author Semprathlon
*/
import java.io.*;
import java.util.*;
public class Main {

/**
* @param args
*/
final static int mod=1000000007;
static int[] a,f;
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
InputReader in=new InputReader(System.in);
PrintWriter out=new PrintWriter(System.out);
int T=in.nextInt();
while(T-->0){
int n=in.nextInt();
int sum=0;
a=new int[n+1];
for(int i=1;i<=n;i++){
a[i]=in.nextInt();
sum+=a[i];
}
sum>>=1;
f=new int[sum+1];
f[0]=1;
for(int i=1;i<=n;i++)
for(int j=sum;j>=0;j--)
for(int k=1;k<=j&&k<=a[i];k++){
f[j]+=f[j-k];
f[j]%=mod;
}
out.println(f[sum]);
}
out.flush();
out.close();
}

}
class InputReader{
public BufferedReader reader;
public StringTokenizer tokenizer;

public InputReader(InputStream stream){
reader = new BufferedReader(
new InputStreamReader(stream), 32768);
tokenizer = null;
}

public String next(){
while(tokenizer == null || !tokenizer.hasMoreTokens()){
try{
tokenizer = new StringTokenizer(
reader.readLine());
}catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}

public int nextInt() {
return Integer.parseInt(next());
}

public long nextLong() {
return Long.parseLong(next());
}

}

非常奇怪,找到sum/2可得最优解这个规律就算是成功了一半了

hdu 2089 数位dp

不要62

具有教科书性质的数位dp应用实例。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/** Aug 31, 2015 9:57:30 PM
* PrjName:hdu2089
* @author Semprathlon
*/
import java.io.*;
import java.util.*;
public class Main {
/**
* @param args
*/
final static int maxl=7;
static int[][] f;
static int[] digit;
static void init(){
f=new int[maxl+1][10];
f[0][0]=1;
for(int i=1;i<=maxl;i++)//从低位到高位!
for(int j=0;j<10;j++)
for(int k=0;k<10;k++)
if (k!=4&&!(j==6&&k==2))
f[i][j]+=f[i-1][k];
}
static int solve(int n){
//if (n==0) return 1;
digit=new int[maxl+1];
while(n>0){
digit[++digit[0]]=n%10;
n/=10;
}
int res=0;
for(int i=digit[0];i>0;i--){//从高位到低位!
for(int j=0;j<digit[i];j++)
if(j!=4&&!(j==2&&digit[i+1]==6))//限制前j位,枚举后digit[0]-j位
res+=f[i][j];
if(digit[i]==4||digit[i]==2&&digit[i+1]==6) break;
}
return res;
}
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
StreamTokenizer in=new StreamTokenizer(new BufferedInputStream(System.in));
PrintWriter out=new PrintWriter(System.out);
init();
while(in.nextToken()!=StreamTokenizer.TT_EOF){
int n=(int)in.nval;
in.nextToken();
int m=(int)in.nval;
if (n==0&&m==0) break;
//out.println(solve(n)+" "+solve(m+1));
out.println(solve(m+1)-solve(n));
}
out.flush();
out.close();
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/** Sep 1, 2015 8:57:53 PM
* PrjName:hdu2089-2
* @author Semprathlon
*/
import java.io.*;
import java.util.*;
public class Main {
/**
* @param args
*/
final static int maxl = 8;
static int[][] f, g;
static int[] digit;
static void init() {
f = new int[maxl + 1][10];
f[0][0] = 1;
g = new int[maxl + 1][10];
g[0][0] = 1;
}
static void getd(int n) {
digit = new int[maxl + 1];
while (n > 0) {
digit[++digit[0]] = n % 10;
n /= 10;
}
}
static int dfs(int d, int r, boolean c) {
if (d == 0) {
if (c)
f[d + 1][r]++;
return 0;
}
if (!(f[d + 1][r] > 0)) {
int add = 0;
int up = c ? 9 : digit[d];
for (int i = 0; i <= up; i++)
if (!(r == 6 && i == 2)) {
if (!(f[d][i] > 0))
dfs(d - 1, i, c || i != up);
if (i != 4)
add += f[d][i];
}
f[d + 1][r] += add;
}
int res = digit[d] == 4 || digit[d] == 2 && digit[d + 1] == 6 ? 0 : dfs(d - 1, 0, false);
for (int i = 0; i < digit[d]; i++)
if (i != 4 && !(i == 2 && digit[d + 1] == 6))
res += f[d][i];
return res;
}
static int solve(int n) {
int res = 0;
getd(n);
return dfs(digit[0], 0, true);
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
StreamTokenizer in = new StreamTokenizer(new BufferedInputStream(System.in));
PrintWriter out = new PrintWriter(System.out);
init();

while (in.nextToken() != StreamTokenizer.TT_EOF) {
int n = (int) in.nval;
in.nextToken();
int m = (int) in.nval;
if (n == 0 && m == 0)
break;
out.println(solve(m + 1) - solve(n));
}
out.flush();
out.close();
}
}
  • 为何生成与统计分两步走?
    因为前i+1位的各种情况以前i位为依据生成,不能打断这个递推的连续性。
    待统计时再筛选所需。
  • 为何solve(m+1)?
    便捷化处理,搜集<m+1的答案即≤m的答案。
  • 为何这个记忆化搜索极易写挂?
    许多人根据数字的可选或不可选来划分状态,而此处为了清晰的体现数位的筛选辄以数字为状态。
    状态的更新与统计仍是分离的。

2013 ACM/ICPC Asia Regional Chengdu Online

1007 F(x)数位DP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/** Aug 22, 2015 5:23:42 PM
* PrjName:hdu4734
* @author Semprathlon
*/
import java.io.*;
import java.util.*;
public class Main {

/**
* @param args
*/
static int[][] f;
static int[] digit;
final static int maxm=4600;
static int fun(int n){
int res=0,tmp=1;
while(n>0){
res+=n%10*tmp;
tmp<<=1;
n/=10;
}
return res;
}
static void init(){
int tmp=1;
f=new int[10][maxm+1];
f[0][0]=1;
for(int i=1;i<10;i++){
for(int j=0;j<=maxm;j++)
for(int k=0;k<=9;k++)
if (j+tmp*k<=maxm)
f[i][j+tmp*k]+=f[i-1][j];
tmp<<=1;
}
for(int i=0;i<10;i++)
for(int j=1;j<=maxm;j++) f[i][j]+=f[i][j-1];
}
static int[] getdg(int n){
int[] res=new int[10];
while(n>0){
res[++res[0]]=n%10;
n/=10;
}
return res;
}
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
InputReader in=new InputReader(System.in);
PrintWriter out=new PrintWriter(System.out);
init();
int T=in.nextInt(),cas=0;
while(T-->0){
int A=in.nextInt();
int B=in.nextInt();
int m=fun(A);
digit=getdg(B);
int ans=0,tmp=1<<digit[0];
for(int i=digit[0];i>=1;i--){
tmp>>=1;
for(int k=0;k<digit[i];k++){

if (m-k*tmp>=0){
ans+=f[i-1][m-k*tmp];
}
}
m-=digit[i]*tmp;
if (m<0) break;

}
if (m>=0) ans++;
out.println("Case #"+(++cas)+": "+ans);
}
out.flush();
out.close();
}

}

磕磕绊绊的,到底有几大难?
期初是有过转化为背包问题的尝试,但是忽视了数位DP的处理手段;可先扩大枚举范围,再从中筛选。
预处理的两套循环不能杂糅在一起,因为先通过递推求了第i位、限制F(x)==j的解,然后才相加得到第i位、限制F(x)≤j的解。
筛选时注意“小于”的枚举方式。
最后还应留意B为可行解的条件。

1010 A Bit Fun

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/** Aug 22, 2015 4:28:18 PM
* PrjName:hdu4737
* @author Semprathlon
*/
import java.io.*;
import java.util.*;
public class Main {

/**
* @param args
*/
static int[] a;
static Queue<Integer> que=new LinkedList<Integer>();
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
InputReader in=new InputReader(System.in);
PrintWriter out=new PrintWriter(System.out);
int T=in.nextInt(),cas=0;
while(T-->0){
int n=in.nextInt();
int m=in.nextInt();
a=new int[n+1];
que.clear();
int ans=0;
for(int i=1;i<=n;i++){
a[i]=in.nextInt();
int k=que.size();
for(int j=0;j<k;j++){
int tmp=que.poll()|a[i];
if (tmp<m) que.add(tmp);
}
if (a[i]<m) que.add(a[i]);
ans+=que.size();
}
out.println("Case #"+(++cas)+": "+ans);
}
out.flush();
out.close();
}

}

并没有实现有些题解中所说的O(nlogn)或O(30n)的算法,但总的运行时间还是较短的?

hdu 5115 Dire Wolf 区间DP

2014ACM/ICPC亚洲区北京站
Dire Wolf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* 2015年7月18日 上午9:55:52
* PrjName:hdu5115
* @ Semprathlon
*/
import java.io.*;
public class Main {
final static long inf=0x7FFFFFFFFFFFFFFFL;
static long min(long a,long b){
return Math.min(a, b);
}
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
StreamTokenizer in=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
in.nextToken();
int T=(int)in.nval,cas=0;
int[] a,b;
long[][] f;
while(T-->0){
in.nextToken();
int n=(int)in.nval;
a=new int[n+2];
b=new int[n+2];
f=new long[n+2][n+2];
for(int i=1;i<=n;i++){
in.nextToken();
a[i]=(int)in.nval;
}
for(int i=1;i<=n;i++){
in.nextToken();
b[i]=(int)in.nval;
}
f[1][1]=a[1]+b[2];
f[n][n]=a[n]+b[n-1];
for(int i=2;i<n;i++)
f[i][i]=a[i]+b[i-1]+b[i+1];
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++)
f[i][j]=inf;
for(int j=0;j<=n;j++)
for(int i=1;i+j<n+1;i++)
for(int k=i;k<=i+j;k++){
f[i][i+j]=min(f[i][i+j],f[i][k-1]+f[k+1][i+j]+a[k]+b[i-1]+b[i+j+1]);
//out.print(f[i][i+j]+" ");
}
/*for(int i=0;i<=n+1;i++){out.println();
for(int j=0;j<=n+1;j++)
out.print(f[i][j]+"\t");
}*/


/*for(int i=0;i<n;i++)
for(int j=1;j<n-i;j++){
if (j==1)
min(f[j][j+i],f[j+1][j+i]+a[j]);
if (j>1)
min(f[j][j+i],f[j+1][j+i]+a[j]+b[j-1]);
if (i+j<n)
min(f[j][j+i],f[j][j+i-1]+a[j+i]+b[j+i+1]);
if (i+j==n)
min(f[j][j+i],f[j][j+i-1]+a[j+i]);
for(int k=j+1;k<j+i;k++)
min(f[j][j+i],f[j][k-1]+a[k]+f[k+1][j+i]);
}*/
out.println("Case #"+(++cas)+": "+f[1][n]);
out.flush();
}

out.close();
}
}

贪心真的是要贪婪死了。。。
已消除区段。。。其实对后续操作没有影响,符合无后效性。