20141022

  

  TYVJ1125  JR‘s chop

  http://www.tyvj.cn/Problem_Show.aspx?id=1125

  先将每根筷子按长度排序

  设dp[i][j][0]为前i个筷子取j对且不取第i个的最小解

   dp[i][j][1]为前i个筷子取j对且取第i个的最小解

   dp[i][j][0] = min(dp[]i-1[j][0],dp[i-1][j][1])

   dp[i][j][1] = min(dp[k][j-1][0],dp[k][j-1][1])+b[i][k+1] | (j-1)*2<=k<=i-2

   b[i][k] 为第i个和第k个筷子的平方差的和

  

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <iostream>
 5 #include <algorithm>
 6 using namespace std;
 7 const int maxn = 105;
 8 const int maxv = 1005;
 9 const int INF = 0x3f3f3f3f;
10 const int mod = 1e9+7;
11 typedef long long LL;
12 int a[maxn],dp[maxn][maxn][2];
13 int b[maxn][maxn];
14 int main()
15 {
16 //    freopen("in.txt","r",stdin);
17     int n,m;
18     while(cin>>n>>m)
19     {
20         m+=3;
21         if(n<m*2){
22             printf("-1\n");
23             break;
24         }
25         memset(dp,0x3f,sizeof(dp));
26         memset(b,0,sizeof(b));
27         for(int i = 1;i<=n;++i)scanf("%d",a+i);
28         sort(a+1,a+1+n);
29         for(int i = 1;i<=n;++i)for(int j = 1;j<=i;++j)
30             b[i][j] = (a[i]-a[j])*(a[i]-a[j]);
31         dp[2][0][1] = 0;
32         dp[2][1][1] = b[2][1];
33         for(int i = 3;i<=n;++i)
34             for(int j = 1;j<=i/2;++j)
35             {
36                 dp[i][j][0] = min(dp[i-1][j][0],dp[i-1][j][1]);
37                 for(int k = (j-1)*2;k<=i-2;k++)
38                 {
39                     int t = min(dp[k][j-1][1],dp[k][j-1][0])+b[i][k+1];
40                     dp[i][j][1] = min(t,dp[i][j][1]);
41                 }
42             }
43         printf("%d\n",min(dp[n][m][0],dp[n][m][1]));
44     }
45     return 0;
46 }

    TYVJ 1213 嵌套矩形

    http://www.tyvj.cn/Problem_Show.aspx?id=1213

    水题

    

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <iostream>
 5 #include <algorithm>
 6 using namespace std;
 7 const int maxn = 2005;
 8 const int maxv = 1005;
 9 const int INF = 0x3f3f3f3f;
10 const int mod = 1e9+7;
11 typedef long long LL;
12 struct node
13 {
14     int x;
15     int y;
16 }a[maxn];
17 int cmp(const void *a,const void *b)
18 {
19     struct node *aa = (struct node *)a;
20     struct node *bb = (struct node *)b;
21     if(aa->x==bb->x)return aa->y-bb->y;
22     return aa->x-bb->x;
23 }
24 int dp[maxn];
25 int main()
26 {
27 //    freopen("in.txt","r",stdin);
28     int n;scanf("%d",&n);
29     for(int i = 1;i<=n;++i)
30     {
31         int x,y;
32         scanf("%d%d",&x,&y);
33         if(x>y)swap(x,y);
34         a[i].x = x;
35         a[i].y = y;
36     }
37     qsort(a+1,n,sizeof(a[1]),cmp);
38
39     for(int i = 1;i<=n;++i)
40     {
41         dp[i] = 1;
42         for(int j = 1;j<i;++j)if(a[i].x>a[j].x && a[i].y>a[j].y)
43             dp[i] = max(dp[i],dp[j]+1);
44     }
45     int ans = 0;
46     for(int i = 1;i<=n;++i)
47         ans = max(ans,dp[i]);
48     cout<<ans<<endl;
49     return 0;
50 }

    

    TYVJ1095 美元

    http://www.tyvj.cn/Problem_Show.aspx?id=1095

    水题

    设dp[i][0]表示第i天以美元为单位最多的钱

     dp[i][1]表示第i天以马克为单位最多的钱

    

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <cstdlib>
 4 #include <iostream>
 5 #include <algorithm>
 6 using namespace std;
 7 const int maxn = 2005;
 8 const int maxv = 1005;
 9 const int INF = 0x3f3f3f3f;
10 const int mod = 1e9+7;
11 typedef long long LL;
12 double dp[maxn][2];
13 int main()
14 {
15 //    freopen("in.txt","r",stdin);
16     int n;cin>>n;
17     for(int i = 1;i<=n;++i)
18     {
19         int t;scanf("%d",&t);
20         if(i==1)
21         {
22             dp[i][0] = 100;
23             dp[i][1] = t*1.0;
24             continue;
25         }
26         dp[i][0] = max(dp[i-1][0],dp[i-1][1]/t*100);
27         dp[i][1] = max(dp[i-1][1],dp[i-1][0]/100*t);
28     }
29     printf("%.2lf\n",dp[n][0]);
30     return 0;
31 }
时间: 2024-08-07 21:20:56

20141022的相关文章

小知识点日志(2014-10-22~2015-4-7)

上一篇 小知识点日志(2013-6-24~2014-10-11) 2014-10-22 17:51:46 1.函数命名:使用 LayerObjectOperation的命名方法,例如SlotFileRead.如果是面向对象的,通常是Layer字段在类名里表示了,而ObjectOperation通常表示成OperationObject,例如" CSlot slot; slot.readFile(); " 2.svn bug 3.mac实用工具:dash alfred 4.xcode Pe

谢尔宾斯基三角形,“混沌游戏”实现 2014-10-22

请教了一下@李劲 学长用啥图形库,学长推荐了EasyX,我就试了试做这个,原物是从<混沌与分形——科学的新疆界>p24页看到的. 本来还想做的更动态一些,但是没搞清楚画出的线如何删掉,干脆就不划线了.用上下键可调速. 疑问: ①.如何有效地将程序暂停很短的时间?貌似Sleep函数只能最短暂停10ms左右.我用空循环模拟了暂停,但在VS的Release生成时就毫无效果,不知道是空循环的问题还是其他问题(我怀疑后者). ②.TCHAR如何用itoa等函数?(有wcscpy等TCHAR类型可使用的函

AngularJS 2014-10-22

tool: http://www.oschina.net/p/angularjs-eclipse module: Jasmine resource: 官方教程 http://woxx.sinaapp.com/ 种子项目 https://github.com/angular/angular-seed 开源中国的 AngularJS 优秀文章汇总 http://www.oschina.net/news/54687/oschina-angular-articles-summary

【英语】20141022 生词

focus industry industrialization [英]?n?d?str??la?'ze??n n. 工业化 economic growth reduce v. reduction [英]r?'d?k?n n. 减少;降低;[数学]约简;[摄影术]减薄 extreme [英]?k'stri:m n. 极端;困境;[数]极限值;[常用复数]在两末端的事物 adj. 极端的,过激的;极限的,非常的;末端的;(政治上)急进的 poverty [英]?p?v?ti n. n.贫穷;缺乏,

检测QQ在线状态脚本(20141022测试成功)

import time,datetime import urllib2 def chk_qq(qqnum): chkurl = 'http://wpa.paipai.com/pa?p=1:'+`qqnum`+':17' a = urllib2.urlopen(chkurl) length=a.headers.get("content-length") a.close() print datetime.datetime.now() print length if length=='234

概率dp HDU 3853

H - LOOPS Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3853 Appoint description:  System Crawler  (2014-10-22) Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wa

概率dp ZOJ 3640

Help Me Escape Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3640 Appoint description:  System Crawler  (2014-10-22) Description Background     If thou doest well, shalt thou not be accepted? an

1、MyBatisNet的安装使用

用到的几个DLL按理说应该到官网下载,但这个官网是谷大哥的,不知道是不是被屏蔽,总打不开,幸好从别人的程序里拷过来一份,直接放在自己的程序里就行! 程序结构如下: Providers.config,SqlMap.config,TUser.xml是必须的.TUser.xml为对应TUser.cs实体类的配置文件(请注意文件名,类名最好要一样,不一样的情况貌似会出错) providers.config 如下: <?xml version="1.0" encoding="ut

智能NDS服务器的搭建——三大运营商线路分流解析DNS

在我们中国电信运营商不止一家,有电信.移动.网通,但我们在访问互联网资源时,有时候就会现跨网访问的情况,但有时间跨网访问速度是奇慢的.所以我们的网站运营商,也会在网站的服务器上同时配上三大电信运营商的线路,如此一来,电信用户访问的时候就走电信的出口,移动用户访问的时候就走移动的出口,网通通用户访问的就走网通的出口,这样也就很好的解决了跨网访问速度奇慢的问题的了.但这里其实就用到了,如何让DNS在解析地址的过程中智能的去判断哪个运营商的用户走哪条线路了.今天在这里给大家模拟实现一下,智能DNS如何