解题思路:深搜一波,超时哈哈91%
注意事项:
参考代码:
import java.util.Scanner;
public class Main {
private static int vu=0;
private static int[] a;
private static int[][] v=new int[1004][2];
private static int mac=0;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n=input.nextInt(),s=input.nextInt(),c=input.nextInt(),b=input.nextInt();
a=new int[]{c,-b};
for (int i = 1; i <1000000; i++) {
mac=i;
dfs(i,1,n,s);
}
System.out.println(vu%100000007);
}
private static void dfs(int mun, int count,int n, int s) {
if(mac==s&&count==n){
vu++;
return;
}
else if(count==n){
return;
}
else{
for (int i = 0; i <2; i++) {
if(v[count][i]==0){
v[count][i]=1;
mac+=mun+a[i];
dfs(mun+a[i],count+1,n,s);
mac-=mun+a[i];
v[count][i]=0;
}
}
}
}
}
0.0分
4 人评分
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:615 |
简单的a+b (C语言代码)浏览:599 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:1257 |
三角形 (C++代码)递归(存在大量重复计算,容易出现时间超限)浏览:781 |
【计算两点间的距离】 (C语言代码)浏览:1494 |
字符逆序 (C语言代码)浏览:646 |
1157题解浏览:716 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:518 |
多组数据新方法浏览:355 |
自编的贪吃蛇小游戏,代码装上easyx图形库就能运行。浏览:942 |